Re: Re: Kernel module: return a number from a device

From: Warner Losh <imp_at_bsdimp.com>
Date: Sun, 07 Apr 2024 04:21:12 UTC
On Sat, Apr 6, 2024 at 3:00 PM Rocky Hotas <rockyhotas@tilde.team> wrote:

> On apr 06 14:39, Warner Losh wrote:
> > When this happens, hit ^t (control t). That will give a traceback of the
> > call stack which may help you track down where it is hanging (most likely
> > something is sleeping waiting for an event).
>
> Thanks! It seems that cat itself is hanging (so, uiomove can still be
> the
> culprit...):
>
> $ cat rolld
> Opened device "rolld" successfully.
> load: 0.44  cmd: cat 13392 [running] 7.67r 1.25u 6.39s 38% 1936k
>

running means there's a tight loop somewhere... uiomove doesn't do that. It
is a bunch of ifs that go to a copyout.  Arc4random shouldn't either. I'd
add printf to see where.




> I also tried to modify rolld_read using only char variables:
>
> static int
> rolld_read(struct cdev *dev __unused, struct uio *uio, int ioflag
> __unused)
> {
>         char random_out;
>         char random_item;
>         int error;
>
>         random_item = (char) arc4random();
>         random_out = random_item % d_size;
>
>         if ((error = uiomove(&random_out, 1, uio)) != 0)
>                 uprintf("uiomove failed!\n");
>
>         return (error);
> }
>
>
> But nothing changed with respect to the first version.
>

This should produce an infinite number of chars...  maybe it is and d_size
is 1 and they are all NULs. Try cat -v.

Warner


> Rocky
>
>