Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3697770ybn; Fri, 27 Sep 2019 10:00:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqo/QYU2xxdHtxegxrreZkdYl/yvIUh/LkZrwgVdPCQ/93P1omqStMCa02kZU8l9c4w0xr X-Received: by 2002:a50:eb44:: with SMTP id z4mr5556650edp.207.1569603626497; Fri, 27 Sep 2019 10:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569603626; cv=none; d=google.com; s=arc-20160816; b=eCnjEchzUMUHM/aGgjsOqz22bEmMC1beO152mPqPnNOWmvvTIGBb6A+omSZmBxJge/ lAToA9VN+HYRSYQITuu9LrlgdZAqDsl69oA7uMe3HrkF9tzReRnO0sXb40cJjnbkUie0 DZVaxOFF9ncrzOz1dhY8OKiAxlZuXI3g1k+GJxnyxdwuWqs+ljmBt3l3s+Hg26ECWAzU 5bnGWEEYdGbwdsLRWmlzaGwjTZ/TI/RsseIlLKDhaYfTSLpx76tZ6Yxm6Tx3NXJyDuk3 SdqbhRjpzHMnvCh3aW1JEwwL65n1X2x+bbKt278B8GgtX3zwbujYf2zgx75c48qXaPnQ vgVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=5OA1KelSjRqgKIXP3xwu3b0YMAsja5SrSLeGrDnnW1c=; b=Otg9zcyR/PzpBHKBDIrDdv6wKH+GlqDYDD27YJPIQJWrY9orusi6v5c0JO0EN4HqV7 TwepLK51TuROF7ZnNdBzshmoJZdSfVVSaZvo4t5Z98v7xNwvLK2jeaLS9wrvX1zt/D3j WrST6cmxcComosohMbonZ3X/5/uTYga4J7zQt3k5iT6STDLacPoMJ532MWB/bUVa8aOC 6tLbprDXnnAw4dpYG56mpQKpofgASjRoexKyWghjQVsR2+XlIsJ/MR5BBwtHCUgPzEHR T541gBVfWsoRz3gKe3W7ERuEYF7uJkJW5HyVo+LJexvdk6oTxSnXYtU0hcMSvo9s/hsB zniA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2si1901035edt.408.2019.09.27.10.00.01; Fri, 27 Sep 2019 10:00:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727995AbfI0Q7o (ORCPT + 99 others); Fri, 27 Sep 2019 12:59:44 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:42145 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbfI0Q7o (ORCPT ); Fri, 27 Sep 2019 12:59:44 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id E7E01804F6; Fri, 27 Sep 2019 18:59:26 +0200 (CEST) Date: Fri, 27 Sep 2019 18:59:40 +0200 From: Pavel Machek To: Akinobu Mita Cc: Greg Kroah-Hartman , linux-leds@vger.kernel.org, LKML , "Rafael J. Wysocki" , Jacek Anaszewski , Dan Murphy Subject: Re: [PATCH v2 1/1] leds: remove PAGE_SIZE limit of /sys/class/leds//trigger Message-ID: <20190927165940.GA25928@amd> References: <1568387004-3802-1-git-send-email-akinobu.mita@gmail.com> <1568387004-3802-2-git-send-email-akinobu.mita@gmail.com> <20190927063547.GA1786569@kroah.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="x+6KMIRAuhnl3hBn" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > > > down_read(&triggers_list_lock); > > > down_read(&led_cdev->trigger_lock); > > > > > > - if (!led_cdev->trigger) > > > - len +=3D scnprintf(buf+len, PAGE_SIZE - len, "[none] "); > > > + len =3D led_trigger_format(NULL, 0, true, led_cdev); > > > + data =3D kvmalloc(len + 1, GFP_KERNEL); > > > > Why kvmalloc() and not just kmalloc()? How big is this buffer you are > > expecting to have here? >=20 > The ledtrig-cpu supports upto 9999 cpus. If all these cpus were availabl= e, > the buffer size would be 78,890 bytes. > (for i in `seq 0 9999`;do echo -n " cpu$i"; done | wc -c) >=20 > The intention of this kvmalloc() allocation is to avoid costly allocation > if possible. Sounds good. > > > - else > > > - len +=3D 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? :) >=20 > I don't touch these locks in this patch :) Nor should you :-). > > Just return -ENOMEM above if !data, which makes this much simpler. >=20 > We are holding the two locks, so we need to release them before return. > Which one do you prefer? >=20 > ... > data =3D kvmalloc(len + 1, GFP_KERNEL); > if (data) > len =3D led_trigger_format(data, len + 1, false, led_cdev= ); > else > len =3D -ENOMEM; >=20 > up_read(&led_cdev->trigger_lock); > up_read(&triggers_list_lock); >=20 > if (len < 0) > return len; >=20 > vs. >=20 > ... > data =3D kvmalloc(len + 1, GFP_KERNEL); > if (!data) { > up_read(&led_cdev->trigger_lock); > up_read(&triggers_list_lock); > return -ENOMEM; > } > len =3D led_trigger_format(data, len + 1, false, led_cdev); >=20 > 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.=20 Thanks, Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --x+6KMIRAuhnl3hBn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl2OP/wACgkQMOfwapXb+vIE7ACfZhiMja1kNbemJQ6IkRMMZl3U y8UAnjNyoJVFR2DhWvqFadYDZA93uGyf =d/TE -----END PGP SIGNATURE----- --x+6KMIRAuhnl3hBn--