Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp338350img; Mon, 18 Mar 2019 04:26:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgbm2ZNwkoLK1LD7CNi6qtDWLVxJ2xWmlVnGuiXfM+GK0Ve0WK1rSZZJcAZ7fZB06VRxZm X-Received: by 2002:a63:2bd5:: with SMTP id r204mr17455140pgr.48.1552908401982; Mon, 18 Mar 2019 04:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552908401; cv=none; d=google.com; s=arc-20160816; b=vDnxc2uicfhqwXUw8WKZj6tzTAatHhnsaCQjymEm5exvhZ2/F3EDE33+i64xMfDM2W kEv3W4d/+hYuJr1Qb1wOVpKF+v4qz+UBlu52cTijhSammAL2aF+sANv0bwKtLnYKnNW3 OCpbZNecFa9pBxKM2o8seTyWvfnkh+5wXV4NCu24vcC9ojmvCuHr6egOJX3KBxpHXJ1j J6c3a9ICL45tRPytQrCRUYZ42QPsRI22MO8kRjhdVdM8RkJ92NzHtjLCpWj9EqG7iLEd LwEnqYu9woM4eYyn5Yk90K7UOmNkd++KtejCAoGPNe2myeVYVKqpyWJ8Eg5esRi/S3Qm xMWw== 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=jV30zMnYMvMxd/TpGkeiH1eRxoWmHatgHCjicZFiWgg=; b=DtEGVew0n0YX1jHXMdRgdfX7Tvl2ASexYWGdkd0HLBW+Oss1NquG4hgl+wqhPB5peJ Z9UlYtCuQa1yOso3AfVosWescHz3Pcowd8j+QmSQbMt/h9IxigB2DfH9IKetXM2qhDCp obWyruEESPupXZ0ijgU1EfUNoScItoz/k4bOtfYtOCYrOBcFSuPrnV5Pe39vSwhQTo9b U3fLWCaBRezUvWbVnXJ0ynimxeWs723VEX2L9yrHaOLAKGWLhCTXyYFJ74Xy4nWyvlbj DmtoakHZMZrDJIox5IEt/F6hLxpGByiAhOP89dEVXgjBNpi+rHsw2ofLzHuvIiWmF7ex CeJA== 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 u2si8928647pgp.549.2019.03.18.04.26.25; Mon, 18 Mar 2019 04:26:41 -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 S1727079AbfCRLZW (ORCPT + 99 others); Mon, 18 Mar 2019 07:25:22 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:60472 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbfCRLZW (ORCPT ); Mon, 18 Mar 2019 07:25:22 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 24E908053F; Mon, 18 Mar 2019 12:25:13 +0100 (CET) Date: Mon, 18 Mar 2019 12:25:20 +0100 From: Pavel Machek To: Rasmus Villemoes Cc: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Jacek Anaszewski , LKML , linux-leds@vger.kernel.org Subject: Re: [PATCH v2 3/6] leds: netdev trigger: move newline handling back to device_name_store Message-ID: <20190318112520.GC6101@amd> References: <20190313202615.22883-1-linux@rasmusvillemoes.dk> <20190314140619.3309-1-linux@rasmusvillemoes.dk> <20190314140619.3309-4-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+xNpyl7Qekk2NvDX" Content-Disposition: inline In-Reply-To: <20190314140619.3309-4-linux@rasmusvillemoes.dk> 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 --+xNpyl7Qekk2NvDX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu 2019-03-14 15:06:16, Rasmus Villemoes wrote: > Currently, setting device_name to a 15-character name requires > avoiding a trailing newline (e.g. by using 'echo -n' or 'printf'), > which is inconsistent and potentially surprising. Instead of > potentially including a newline in the copy and then overwriting it, > move the newline detection logic to the sysfs handler itself, and > handle it by passing a smaller buffer size to > netdev_trig_set_device(). >=20 > This also makes netdev_trig_set_device() a better fit for a future > user, which will not need the newline truncation logic. >=20 > We still have to tell userspace we consumed all the bytes it gave us, > so we have to stash the original value of size. >=20 > Signed-off-by: Rasmus Villemoes Acked-by: Pavel Machek > --- > drivers/leds/trigger/ledtrig-netdev.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) >=20 > diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger= /ledtrig-netdev.c > index 21605033e322..c35439291424 100644 > --- a/drivers/leds/trigger/ledtrig-netdev.c > +++ b/drivers/leds/trigger/ledtrig-netdev.c > @@ -114,8 +114,6 @@ static void netdev_trig_set_device(struct led_netdev_= data *trigger_data, > =20 > memcpy(trigger_data->device_name, buf, size); > trigger_data->device_name[size] =3D 0; > - if (size > 0 && trigger_data->device_name[size - 1] =3D=3D '\n') > - trigger_data->device_name[size - 1] =3D 0; > =20 > if (trigger_data->device_name[0] !=3D 0) > trigger_data->net_dev =3D > @@ -134,7 +132,11 @@ static ssize_t device_name_store(struct device *dev, > size_t size) > { > struct led_netdev_data *trigger_data =3D led_trigger_get_drvdata(dev); > + size_t orig_size =3D size; > =20 > + /* Ignore trailing newline */ > + if (size > 0 && buf[size - 1] =3D=3D '\n') > + size--; > if (size >=3D IFNAMSIZ) > return -EINVAL; > =20 > @@ -147,7 +149,7 @@ static ssize_t device_name_store(struct device *dev, > set_baseline_state(trigger_data); > spin_unlock_bh(&trigger_data->lock); > =20 > - return size; > + return orig_size; > } > =20 > static DEVICE_ATTR_RW(device_name); --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --+xNpyl7Qekk2NvDX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlyPgCAACgkQMOfwapXb+vIRmACfZ4lWHdc5ZHtR4AXzUFHbpl8e 7JMAoI1HCEF9d3C3UqsFm8tHqxZjyhUQ =K+os -----END PGP SIGNATURE----- --+xNpyl7Qekk2NvDX--