Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3870086imc; Thu, 14 Mar 2019 07:09:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/lKqcMPqKs6qSqCsFADBbIACRkcNlDC5a0ME0ECMfPGOJik7m0W7Q4/BlbobDN6GLJQht X-Received: by 2002:a17:902:b68d:: with SMTP id c13mr27061624pls.46.1552572580739; Thu, 14 Mar 2019 07:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552572580; cv=none; d=google.com; s=arc-20160816; b=sUrHe1aAQkipoC/vm15Nf+zcmrNJ34JUGk3RepglzYtAlNz8Ur/v6xCwPWDvQ6FVP6 PD3BqEa0xo2EKllzwzsgrbDnOske29Ij/ZvfuYBnT7Jpxmdk2WH8J0E1xld/wZnKs4uP LK+rgMcfiYykS4xd45tMhbUdm9gr5ZgIa7SPx9z0d7V+lHQwZGqZFx9S9ZDt9KIHgQXg XxuF2wum3/3G7ryQpiWCM+8i4I7ID6wTweQmR+LPSqHO2YDPYgLkfdKoJtDLMoKCoxVX x8xOohy50lhhY2bshi6GdyC1RYEZBB1dhIUT0Gl6vtYJgX/9/4MOl6Ew7a0edVj9jJE+ xKrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ugGKi5F3qXScZthoWLEHSmP8Nu33dGLtFdl4STCni7Y=; b=QSclM8tFmOXHOBOVDdUxGR2f7vyDNhUKjBTLOAfxJqhhXWNB2r8j5zoEHeCYDmccMn zzF0zd76M7ZQaG0dxUhuI2/2IQnp2JmUbJFoUbM5nvSu+JnA+2pd6l6IkraoarXG25l9 nMcQFveQ1XzU/ipBB82Q1adZ++g8Viq3wufVQIhkPyHmLr8MiVWtXH5cUGAfvI523CcP ZJuOIwYA1NhhRaXY/gH8+78RIL/fbvdlRABvKfo3f5FISl9suFwHeC7HyBNQIMG0ir/P z5eLLXJYMGmu+KLOHRPd+NpeCrxZ7xqi3jMXihFKa5rKTI8hpEPK4U9VBKW0tN+Mqw3U CxHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=B2aH6ObB; 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 i4si12093285pgs.408.2019.03.14.07.09.25; Thu, 14 Mar 2019 07:09:40 -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; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=B2aH6ObB; 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 S1727732AbfCNOGx (ORCPT + 99 others); Thu, 14 Mar 2019 10:06:53 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:34435 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727586AbfCNOG3 (ORCPT ); Thu, 14 Mar 2019 10:06:29 -0400 Received: by mail-lf1-f67.google.com with SMTP id y18so4347105lfe.1 for ; Thu, 14 Mar 2019 07:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ugGKi5F3qXScZthoWLEHSmP8Nu33dGLtFdl4STCni7Y=; b=B2aH6ObBaC1172QGpMisaDebLrcbytqQT/FKIKSuV+U6ps4USRVv3PkPQe/uXrkpwa yeBqa0lso6v4mjsnhbehFbEiqz5TyB59ox+piIIFDH86db5aykXOl6+UQ8+4TNF0Ua7Q iLPZaRq09A6BlybsDJeE3HjpmN0pq88OEVxUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ugGKi5F3qXScZthoWLEHSmP8Nu33dGLtFdl4STCni7Y=; b=da10LEQv9YIvKN9BnuClx2Z6VLeFpzm5sX41QyZ97Ee5JtUfueaVXHMYwrjTh2K3f3 w7xh+DmgI19xNEQ2k9riRMjHQ36Kh8jbOWOt+4NVG+sCU98P9Gwyg/IDDcvxFhDx6tF+ IIA5OFdgyEDBg4y8CXQP5BoOvH3xj+2LPk9UMfdZRuIRlkZS0++uQWfRsF6IgeDqEvOC O6neV2WgFUz/S19R+jbDWQ/eH62H3Wr/N8Mk0Bh2qbNF0qAb0Hu+J7vSHJI9OOsaXZ8B myqXC3//JSC7eOV8757JDSKBnsyjAhxhPMpxgU36JUfVUl4GcXtlmvH78Z03XISLSZgo IMtw== X-Gm-Message-State: APjAAAVa8xr8IcLfQELbAv2f+W6ESZrx4kLqJJEA2ipaQ/088rjO3epj iemTQvjRIn4HV1PX+fUysOrWWA== X-Received: by 2002:ac2:52a1:: with SMTP id r1mr22361245lfm.155.1552572387367; Thu, 14 Mar 2019 07:06:27 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id t14sm2733709lfe.51.2019.03.14.07.06.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 07:06:26 -0700 (PDT) From: Rasmus Villemoes To: Pavel Machek , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Jacek Anaszewski Cc: LKML , Rasmus Villemoes , linux-leds@vger.kernel.org Subject: [PATCH v2 3/6] leds: netdev trigger: move newline handling back to device_name_store Date: Thu, 14 Mar 2019 15:06:16 +0100 Message-Id: <20190314140619.3309-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190314140619.3309-1-linux@rasmusvillemoes.dk> References: <20190313202615.22883-1-linux@rasmusvillemoes.dk> <20190314140619.3309-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). This also makes netdev_trig_set_device() a better fit for a future user, which will not need the newline truncation logic. We still have to tell userspace we consumed all the bytes it gave us, so we have to stash the original value of size. Signed-off-by: Rasmus Villemoes --- drivers/leds/trigger/ledtrig-netdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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, memcpy(trigger_data->device_name, buf, size); trigger_data->device_name[size] = 0; - if (size > 0 && trigger_data->device_name[size - 1] == '\n') - trigger_data->device_name[size - 1] = 0; if (trigger_data->device_name[0] != 0) trigger_data->net_dev = @@ -134,7 +132,11 @@ static ssize_t device_name_store(struct device *dev, size_t size) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); + size_t orig_size = size; + /* Ignore trailing newline */ + if (size > 0 && buf[size - 1] == '\n') + size--; if (size >= IFNAMSIZ) return -EINVAL; @@ -147,7 +149,7 @@ static ssize_t device_name_store(struct device *dev, set_baseline_state(trigger_data); spin_unlock_bh(&trigger_data->lock); - return size; + return orig_size; } static DEVICE_ATTR_RW(device_name); -- 2.20.1