Hi! > > > down_read(&triggers_list_lock); > > > down_read(&led_cdev->trigger_lock); > > > > > > - if (!led_cdev->trigger) > > > - len += scnprintf(buf+len, PAGE_SIZE - len, "[none] "); > > > + len = led_trigger_format(NULL, 0, true, led_cdev); > > > + data = kvmalloc(len + 1, GFP_KERNEL); > > > > Why kvmalloc() and not just kmalloc()? How big is this buffer you are > > expecting to have here? > > The ledtrig-cpu supports upto 9999 cpus. If all these cpus were available, > the buffer size would be 78,890 bytes. > (for i in `seq 0 9999`;do echo -n " cpu$i"; done | wc -c) > > The intention of this kvmalloc() allocation is to avoid costly allocation > if possible.
Sounds good.
> > > - else
> > > - len += scnprintf(buf+len, PAGE_SIZE - len, "%s ",
> > > - trig->name);
> > > - }
> > > up_read(&led_cdev->trigger_lock);
> > > up_read(&triggers_list_lock);
> >
> > Two locks? Why not 3? 5? How about just 1? :)
>
> I don't touch these locks in this patch :)
Nor should you :-).
> > Just return -ENOMEM above if !data, which makes this much simpler.
>
> We are holding the two locks, so we need to release them before return.
> Which one do you prefer?
>
> ...
> data = kvmalloc(len + 1, GFP_KERNEL);
> if (data)
> len = led_trigger_format(data, len + 1, false, led_cdev);
> else
> len = -ENOMEM;
>
> up_read(&led_cdev->trigger_lock);
> up_read(&triggers_list_lock);
>
> if (len < 0)
> return len;
>
> vs.
>
> ...
> data = kvmalloc(len + 1, GFP_KERNEL);
> if (!data) {
> up_read(&led_cdev->trigger_lock);
> up_read(&triggers_list_lock);
> return -ENOMEM;
> }
> len = led_trigger_format(data, len + 1, false, led_cdev);
>
> up_read(&led_cdev->trigger_lock);
> up_read(&triggers_list_lock);
Second one is better. Using goto to jump to error path doing cleanups
is also acceptable.
Thanks,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures)
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
signature.asc
Description: Digital signature

