Message ID | 20240126231348.281600-4-thepacketgeek@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-40810-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp212701dyb; Fri, 26 Jan 2024 15:35:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1SL9dO+M+moa/kiVEFzPmIfKAnTYfR4TA7ag5/dB1hKo+DIi8uoX9Q+Sd7VO+fiafqUhf X-Received: by 2002:a62:f20b:0:b0:6db:b1f3:fb66 with SMTP id m11-20020a62f20b000000b006dbb1f3fb66mr639645pfh.8.1706312159099; Fri, 26 Jan 2024 15:35:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706312159; cv=pass; d=google.com; s=arc-20160816; b=ry7alvGk0Zy69uo51e+3uqsHzp9hBTkgWaKvFB0CAbPhyRUWRGXAw2C6RjJazHUhOo 1QvKcIYNbz39ZGrPcHvKR8fo+0jNJ+g4jGRR3wxoyuMlZmACRTaNUqQon8h68QQIJYrt IYgY6EoVKb572XEc/DUkCvnDfBCrV8wIq/gaFRUdyx8nZOhgDDzs2c0JEon1hGfvTOWt /jygOOr7j2z7wEyEN6RHWFrnx+d+6W3pZTIuDgIxcCm2QJa5Xaf5mX/8VV/NdgAStit9 brn5s+oGBbBcu/t99SK2XlcfiLeNPx2EI2MtLZZY/KMSRSD64X4Pdds5nUvZUpOIhnaN nYzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=aZZIgE9h2jQLSmHO3bzM7GbmlOxYLfQCD/fuB/DQM9s=; fh=+EB6oBnXtBrxaPMIm1rb1kOyvjkddCLSgL4/UeSWQvM=; b=nghMgt1IIYGCVeoirWjKDKq9F8Tsdtikf2Ymd4pvrcJgWgbzdN1vfaIOJIdrEMvcwV o5KU6xrpUJ7mx+as4B5zv4rHxy6lPzNPUzukkgtS8/EZw5GC6u9dzFu63txO5FusM48v o8uMsUDVSuDKokqKdM++464vpmJstOSoNbQu0sudIhDoUGPF0UHItxz7X6QS3Nl+bb5k w7AIlGSNaIJaHJIn/bV8AEIFB4PHTBCHuQGsWXukTDyMXKJ2dNB0UmZX+40FsqeFt3q3 81Be2Dwo/8eytyHIn6wz6/7oKo72m+En1LWQ6m4IpDQ/u428h+PAMK8fHdHQg9aaWoEu c02g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hGyWAaVv; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-40810-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b7-20020aa78ec7000000b006de0dc5a5acsi339223pfr.129.2024.01.26.15.35.58 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 15:35:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40810-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hGyWAaVv; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-40810-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 23020288666 for <ouuuleilei@gmail.com>; Fri, 26 Jan 2024 23:15:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 311F75B20E; Fri, 26 Jan 2024 23:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hGyWAaVv" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28E6E5A0FD; Fri, 26 Jan 2024 23:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706310840; cv=none; b=EEd/Rsvf2G62HOdeKWSp8oYbmQuB3uOr8OgXu41n/ua3xD/qRlvffUrQztwNpS6GDMFUUvtd9mQgsnZzzQNCg1xa0uQbrOqPxHW/41XaE3KDRfqejEb3AmpgbN3YNt5TA9yks532aAqALrtbEM7wuoeBvbc2c6EUQE9/TMU1rxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706310840; c=relaxed/simple; bh=mPmolvHAcBMTIShhgLdXXMOUD8GBeSY8wUZZNyXtmXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J9wcMqFKVJGC5sn4v06DuZirv0LFh0feHyZZxn9ZONRXcKa3ISnnXVqiyVZEK/6xZ2fF51N7/aP1HvNsLJBH4NgCwRN1PP8EYk4tj/FU9meEdklyjn/RMhv35T0YR/JfgtfAAARa+UFn14TEL5y/y4FA5NgLfxx4Um5UFYuxou4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hGyWAaVv; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d89518d3b1so5883815ad.0; Fri, 26 Jan 2024 15:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706310838; x=1706915638; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aZZIgE9h2jQLSmHO3bzM7GbmlOxYLfQCD/fuB/DQM9s=; b=hGyWAaVvZQNrrxP7Un4wFXI8kbYJUSEBvlY0oQg+18okqMTikxGrl2uVcgyhnljyz0 Ol+zVxwsqtirwthPvkoDrgMzv1sfotWsON3rqRLQUJl8FNgmzdDZe5rcC0SjIAhx7shp 2BbB6b5+D9E6wMAQIUhfPNTXt33kpx3dMV834Ofg3VUQ8biR0h7U/c30RJSB+gqqELVb mx2hLR+VrH+s5MTnD+yFaThi9GK0gbdTx7pm43jknVPOTIRwu5yQ0hnnKLLJgUSgJHir /owYo9DUpM2jM+k75Qht8vzlX60EUTsytRmlkIJtG1zkuAGjjxJePgKqFKUwxUTGIv0o Fg2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706310838; x=1706915638; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aZZIgE9h2jQLSmHO3bzM7GbmlOxYLfQCD/fuB/DQM9s=; b=OAh1EvnhEbemyLxY/+OS93NslwVxZF4Un+31WpAGRw1ytEV0SApB0KjaScnNtziCeC r22LTiA5KK3L7pqftU16z4sRJ6PYamYxxHTG8yApnXe1F47pFE/yPiOfXq3qETQiawOX 3Gum26AaCcA++PZsQjB9+FATpNUCQmpuKlH/0yrsDuq7kgQ/UgU6Jf5w8BETg/DOr2ds XSOLabA4Xr1rBl+gd6F/1dbzDmtDOZ7ASCYzQf4fDJD1PzXRzz65AY/75GXz0D019LFW 5+vBAeWouG4S3VJt9lJtRd58ETf6eJBhSyqcZ4jQXktdlN1h5Urcyjanp2xHtg2SWysY LDGA== X-Gm-Message-State: AOJu0YwBfgW6m5wHOvq6YnNbXSW3osr21C+5O/DQjJUnjzDNjIEJbK05 2ZWDVbxRTw6vQbNSrjy7En5+upG5Pm+xSMcUZGUSk/HMZ4BWXtF5 X-Received: by 2002:a17:903:28e:b0:1d0:4802:3b6c with SMTP id j14-20020a170903028e00b001d048023b6cmr733262plr.4.1706310838445; Fri, 26 Jan 2024 15:13:58 -0800 (PST) Received: from localhost ([2601:644:9380:8cd0::7fb4]) by smtp.gmail.com with ESMTPSA id l6-20020a170903244600b001d78813c8a5sm1423159pls.49.2024.01.26.15.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 15:13:58 -0800 (PST) From: Matthew Wood <thepacketgeek@gmail.com> To: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: leitao@debian.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 3/8] net: netconsole: move newline trimming to function Date: Fri, 26 Jan 2024 15:13:38 -0800 Message-ID: <20240126231348.281600-4-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126231348.281600-1-thepacketgeek@gmail.com> References: <20240126231348.281600-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789197978651204707 X-GMAIL-MSGID: 1789197978651204707 |
Series |
netconsole: Add userdata append support
|
|
Commit Message
Matthew Wood
Jan. 26, 2024, 11:13 p.m. UTC
Move newline trimming logic from `dev_name_store()` to a new function
(trim_newline()) for shared use in netconsole.c
Signed-off-by: Matthew Wood <thepacketgeek@gmail.com>
---
drivers/net/netconsole.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
--
2.43.0
Comments
On Fri, Jan 26, 2024 at 03:13:38PM -0800, Matthew Wood wrote: > Move newline trimming logic from `dev_name_store()` to a new function > (trim_newline()) for shared use in netconsole.c > > Signed-off-by: Matthew Wood <thepacketgeek@gmail.com> > --- > drivers/net/netconsole.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > index 085350beca87..b280d06bf152 100644 > --- a/drivers/net/netconsole.c > +++ b/drivers/net/netconsole.c > @@ -230,6 +230,16 @@ static struct netconsole_target *to_target(struct config_item *item) > struct netconsole_target, group); > } > > +/* Get rid of possible trailing newline, returning the new length */ > +static void trim_newline(char *s, size_t maxlen) > +{ > + size_t len; > + > + len = strnlen(s, maxlen); > + if (s[len - 1] == '\n') > + s[len - 1] = '\0'; > +} I am thinking about this one. Should we replace the first `\n` in the file by `\0` no matter where it is? This will probably make it easier to implement the netconsd, where we know it will be impossible to have `\n` in the userdata. Maybe something as: static inline void trim_newline(char *str) { char *pos = strchr(str, '\n'); if (pos) *pos = '\0'; } All in all, this is a good clean up, which make the code easier to read. Thanks!
On Tue, Jan 30, 2024 at 1:16 AM Breno Leitao <leitao@debian.org> wrote: > > On Fri, Jan 26, 2024 at 03:13:38PM -0800, Matthew Wood wrote: > > Move newline trimming logic from `dev_name_store()` to a new function > > (trim_newline()) for shared use in netconsole.c > > > > Signed-off-by: Matthew Wood <thepacketgeek@gmail.com> > > --- > > drivers/net/netconsole.c | 17 +++++++++++------ > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > > index 085350beca87..b280d06bf152 100644 > > --- a/drivers/net/netconsole.c > > +++ b/drivers/net/netconsole.c > > @@ -230,6 +230,16 @@ static struct netconsole_target *to_target(struct config_item *item) > > struct netconsole_target, group); > > } > > > > +/* Get rid of possible trailing newline, returning the new length */ > > +static void trim_newline(char *s, size_t maxlen) > > +{ > > + size_t len; > > + > > + len = strnlen(s, maxlen); > > + if (s[len - 1] == '\n') > > + s[len - 1] = '\0'; > > +} > > I am thinking about this one. Should we replace the first `\n` in the > file by `\0` no matter where it is? This will probably make it easier to > implement the netconsd, where we know it will be impossible to have `\n` > in the userdata. > > Maybe something as: > > static inline void trim_newline(char *str) > { > char *pos = strchr(str, '\n'); > > if (pos) > *pos = '\0'; > } > > > All in all, this is a good clean up, which make the code easier to read. > Thanks! I like this idea, I agree that only accepting userdata values upto the first newline clears up the expectations for log output and parsing on the receiving side. I would prefer that to the case where multiple values (delimited by newlines) are somehow attempted with a single key, seems like just using additional key/value pairs would be cleaner.
On Wed, Jan 31, 2024 at 8:45 PM Matthew Wood <thepacketgeek@gmail.com> wrote: > > On Tue, Jan 30, 2024 at 1:16 AM Breno Leitao <leitao@debian.org> wrote: > > > > On Fri, Jan 26, 2024 at 03:13:38PM -0800, Matthew Wood wrote: > > > Move newline trimming logic from `dev_name_store()` to a new function > > > (trim_newline()) for shared use in netconsole.c > > > > > > Signed-off-by: Matthew Wood <thepacketgeek@gmail.com> > > > --- > > > drivers/net/netconsole.c | 17 +++++++++++------ > > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c > > > index 085350beca87..b280d06bf152 100644 > > > --- a/drivers/net/netconsole.c > > > +++ b/drivers/net/netconsole.c > > > @@ -230,6 +230,16 @@ static struct netconsole_target *to_target(struct config_item *item) > > > struct netconsole_target, group); > > > } > > > > > > +/* Get rid of possible trailing newline, returning the new length */ > > > +static void trim_newline(char *s, size_t maxlen) > > > +{ > > > + size_t len; > > > + > > > + len = strnlen(s, maxlen); > > > + if (s[len - 1] == '\n') > > > + s[len - 1] = '\0'; > > > +} > > > > I am thinking about this one. Should we replace the first `\n` in the > > file by `\0` no matter where it is? This will probably make it easier to > > implement the netconsd, where we know it will be impossible to have `\n` > > in the userdata. > > > > Maybe something as: > > > > static inline void trim_newline(char *str) > > { > > char *pos = strchr(str, '\n'); > > > > if (pos) > > *pos = '\0'; > > } > > > > > > All in all, this is a good clean up, which make the code easier to read. > > Thanks! > > I like this idea, I agree that only accepting userdata values upto the > first newline clears up the expectations for log output and parsing on > the receiving side. I would prefer that to the case where multiple > values (delimited by newlines) are somehow attempted with a single > key, seems like just using additional key/value pairs would be > cleaner. In practice truncating at the first newline makes no difference as printk, echo, and other methods seem to buffer and write per-line. So in this example, the stored value will be "val2" with or without the suggested change: $ printf "val1\nval2" > userdata/testing/value # This results in two calls to userdatum_value_store, the first with "val1\n" and the second with "val2". "val2" remains as the latest write. $ cat userdata/testing/value val2 I will add a warning about this possibly unexpected behavior in the docs for v3 for the patch
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 085350beca87..b280d06bf152 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -230,6 +230,16 @@ static struct netconsole_target *to_target(struct config_item *item) struct netconsole_target, group); } +/* Get rid of possible trailing newline, returning the new length */ +static void trim_newline(char *s, size_t maxlen) +{ + size_t len; + + len = strnlen(s, maxlen); + if (s[len - 1] == '\n') + s[len - 1] = '\0'; +} + /* * Attribute operations for netconsole_target. */ @@ -424,7 +434,6 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - size_t len; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -435,11 +444,7 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, } strscpy(nt->np.dev_name, buf, IFNAMSIZ); - - /* Get rid of possible trailing newline from echo(1) */ - len = strnlen(nt->np.dev_name, IFNAMSIZ); - if (nt->np.dev_name[len - 1] == '\n') - nt->np.dev_name[len - 1] = '\0'; + trim_newline(nt->np.dev_name, IFNAMSIZ); mutex_unlock(&dynamic_netconsole_mutex); return strnlen(buf, count);