Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp919610rdb; Fri, 26 Jan 2024 15:34:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IExOWWraIOs+sddh2nzbBxosvYKsBkXDdfjvA5bu4lSjkZU/JFRN4dTKeMwby/jrG6C9rYZ X-Received: by 2002:a17:902:ee04:b0:1d8:a6ac:14be with SMTP id z4-20020a170902ee0400b001d8a6ac14bemr1387765plb.67.1706312087401; Fri, 26 Jan 2024 15:34:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706312087; cv=pass; d=google.com; s=arc-20160816; b=kDeL8ZT8FM9uEbY/PJPq5wdIjLEzad+VVggiboL6MSJoTHZ+IcsFdE2/rA6bFQ6hER FqBWyKhtMt5+GugxqcAH+5ERlJE8pnJ/V9lJ2csUjWNBEfjnLrG5pH7FCYMQRp3K4JFg fXOMO6YFXkPKFUfq137A+WLSpEgzDVUsi33jgOOibftbGB/H3sKMlgc529rI+Tg5f8tS +VoyIIo5DrHdbTv9jp1nqmp9pJsIbPw1gMU1ALKjfhM/ya+gQtmbCEZOdyZ9u+7ttHTv 73JI8IZgAP+63C7PuIIFxXLRT9NzV6qObiW/Wkm4JrlhMtIoL/HlZiTgEem+r4JwTfxA sxpg== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u68-20020a637947000000b005d833363035si1359858pgc.790.2024.01.26.15.34.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 15:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40810-linux.lists.archive=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 B2C302876A7 for ; Fri, 26 Jan 2024 23:14:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54E0D5A79F; Fri, 26 Jan 2024 23:14:01 +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 To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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'; +} + /* * 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); -- 2.43.0