tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Kernel doesn't call spi driver's _match() and _attach()



On Tue Sep 17, 2024 at 5:51 PM MSK, Valery Ushakov wrote:
> Since your driver's attach was never called, your mydev_open should
> have never returned success.  sc = device_lookup_private in mydev_open
> should have returned null to you and your open should detect that and
> fail:

Thanks, I've added this check.

> > int
> > mydev_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *lwp)
> > {
> > 	struct mydev_softc *sc;
> >	sc = device_lookup_private(&mydev_cd, minor(dev)); /* BANG! */
> >	...
>
> It's likely it goes bang a bit further down, b/c you didn't check that
> sc is valid?  Again, sc should have been NULL here and the driver
> should check that.

You're right, it was because of this call to aprintf_normal_dev() later:

	aprintf_normal_dev(sc->sc_dev, "mydev_ioctl() called.");

To be more precise, because of `sc->sc_dev` (sc was NULL at the moment).

Even after i got kernel to call mydev_attach(), there was nearly the same
error, but now inside netbsd:strlen(). Trace showed that it was called
by aprintf_normal_dev().

This time it was purely my mistake: I forgot to save `self` in
mydev_attach() function:

	sc->sc_dev = self;

Once that was done, everything seems to work fine for now.

Didn't do any actual SPI transactions yet by the way.

-Nikita


Home | Main Index | Thread Index | Old Index