From: Pavel Machek <pavel@denx.de>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-leds@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Dan Murphy <dmurphy@ti.com>
Subject: Re: [PATCH v2 1/1] leds: remove PAGE_SIZE limit of /sys/class/leds/<led>/trigger
Date: Fri, 27 Sep 2019 18:59:40 +0200 [thread overview]
Message-ID: <20190927165940.GA25928@amd> (raw)
In-Reply-To: <CAC5umyjdM1+4nPg_6UaCjcpikESamdA_ZpmP4Xfjx7_-1f=+0A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2370 bytes --]
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
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2019-09-27 16:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-13 15:03 [PATCH v2 0/1] leds: fix /sys/class/leds/<led>/trigger Akinobu Mita
2019-09-13 15:03 ` [PATCH v2 1/1] leds: remove PAGE_SIZE limit of /sys/class/leds/<led>/trigger Akinobu Mita
2019-09-24 21:30 ` Jacek Anaszewski
2019-09-27 6:27 ` Greg Kroah-Hartman
2019-09-27 6:35 ` Greg Kroah-Hartman
2019-09-27 16:47 ` Akinobu Mita
2019-09-27 16:59 ` Pavel Machek [this message]
2019-09-27 17:46 ` Greg Kroah-Hartman
2019-09-28 4:08 ` Akinobu Mita
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190927165940.GA25928@amd \
--to=pavel@denx.de \
--cc=akinobu.mita@gmail.com \
--cc=dmurphy@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).