Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1299272rdb; Wed, 24 Jan 2024 10:33:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGh4MvwuzoGPKsYhIiPUe8oItOYMzcjc26YvfcPtsMQfCdamThpYDTyHaY4lnzOU0N3FNxn X-Received: by 2002:a17:90a:d0c6:b0:28e:850e:7e87 with SMTP id y6-20020a17090ad0c600b0028e850e7e87mr55403pjw.41.1706121236321; Wed, 24 Jan 2024 10:33:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706121236; cv=pass; d=google.com; s=arc-20160816; b=zmcfwqBttBZWlSrGYHYLGNMLP0+cfIf8o/iU127/yl8p5k4yajDLVnWjFpYVIqaXvO A6aysqWVwhObedg45kFSbtPwWGT+xNRBjJSCecA2I4KF0d/lW0yzVvG91YoX2SJCpni1 aUGpzfdFwI6QRsPKkvS//4N1pPfz0OwqayuCgYT4YsUzzSgxVDjQtV02Vgp1C3bjI+x1 HtvpgNaXomVIHy1/cBG1C44qVl0z3qQoHNRQEM1y/kbNciitn7p4V4C3OutNT9lP+DJ9 z+oIhjTLEodkumPI2NQ93Ec6vp3ttZ3C6dxXYEbLU1FiB+ptRRH5T2INBhG1ywnBFhK4 pQaQ== 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=v77jF51yTqnOl3/nOY82fJC7PIH7X2Y2RU7dU3D2hPY=; fh=hqHu0NgCdv//DzQxyVtNZHxZaYencauOntHWP9zRS5U=; b=SmNxXriY2c0nCqcd8vMEcsnXc1YIJA0yrMsZTmkYMi6R/frzMKIRcTrKM5W2g4fAY2 aySYQgjd5zO36XKtDc0uIJtodtLMeNXiD70QrnyBuBxefYHyxRKONTLlEmMtSRo/DWMS hkOlFw7p5TB/i4/C4BzmDNBzMpXvLhOtDLgBMgXc/ptUddxBRQN+eFFCXcN2Og4KBeRe Aew/fZhbPxo282nNLremMV/x7jP1P75kLAHSmIqD1qf631m2GEuTmdknp/lujdzZg26S JTcufJJ3r5rNs9VNh6S47zigCOKZBBTp+NGPMVl9vJvuZL+z10y8VMBHRLHKis57jSIq lRgw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fMbozi4L; 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-37458-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37458-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id cm23-20020a17090afa1700b0028d1c469133si11856777pjb.71.2024.01.24.10.33.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:33:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37458-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fMbozi4L; 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-37458-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37458-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2B202B319B4 for ; Wed, 24 Jan 2024 17:48:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A22BF12A16C; Wed, 24 Jan 2024 17:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fMbozi4L" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 7AE6312A143; Wed, 24 Jan 2024 17:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118441; cv=none; b=Eafep/BjPLLrno/4r96roFaKUTikmN49bGeXAJfSzIS+LxN0tq6/dXmgmUcg9NKLS1zDmQmpe2Dwy655Bx9thaOn2pamF+cwtj8bHF1tWJghb7E/eG5mIw/3ZgHFNQaC1yPrlMUrkrPpxnbQ/LUknsgjrNkIq3vWIOyHYcXYhoA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118441; c=relaxed/simple; bh=/YjWyaqPnZDamee11YunAkZPyfaZp6y28fWxTHZ2aeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QFlonY8OSZJV7yMCNrEhgClVknfhV4FQbU5pgdJjQu/TMlKuTBHzUeDE21dhBGxNtwDTo9ijyeHlEp0wygsOZNfgDAsH4rQRp/I81etgQwttrTSKLMBfQrd6SkmdN+PGK9F3P4zXyFkQ6iDhhfezRUOhQUZGUt1UDvL+01K5R9c= 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=fMbozi4L; arc=none smtp.client-ip=209.85.214.181 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-f181.google.com with SMTP id d9443c01a7336-1d75c97ea6aso23789975ad.1; Wed, 24 Jan 2024 09:47:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706118440; x=1706723240; 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=v77jF51yTqnOl3/nOY82fJC7PIH7X2Y2RU7dU3D2hPY=; b=fMbozi4LrRQ6tGLocq9T/NXkTCc5QXqmI8C8PHgG0d9Qb9jls+tiFh88jXxepwNE90 83bb0Z6JjiB8x5TrfmKrB+YAYvXlHU8LNFECKZWd5AZ3B+Ipr+I8juKWy6W01t9TPLZK jyETS7AJhoenN+FpcKNy5N1iZnIosqu/uSO1b72PzwAwSJHXTaWD7qIzpmFZ7UdVWG+W KC+o2mtEFM4aM6//UUYjculak0m4sZZOS3gvE5qZAGV8WWcCWVv4gUFZ6a+6d6tVNA2G d78P7ZhH8giQNkQnKtFLaH6rNJgYGdi1JPAmuqmf+uklShc4UwgdUw92gx/og7dOJUOY 7bGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706118440; x=1706723240; 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=v77jF51yTqnOl3/nOY82fJC7PIH7X2Y2RU7dU3D2hPY=; b=uhc9ldi7F5BPMYseWvHBurfKwQd/udmCZ9sI23MDbAYc8wsslk73rHl39hr8Fa7L/D j6jOu29cUOe7JZSmvF3g5CHBYP6nPoRllwlJnWxuwBpEo8Jhfj97qi565VAmhja1DPhy KcahE2p9eq0eL0/XfZX7czr8qH/AIzufKu60wdom9BpGIKtASQ4JVJcjVUwNW2zon8mi HWtuLsIA0aJMO3W7YoElwjIdc1xjuwQmDrK2KLNiXTZL8kflf0VbfjCf42mEBdM60/BD woefvJPIhZ5n+cLDrj7XQU5vZf/HuQbrt5CIbEs+jfNlSsnaxjdeh+9YfLsMAgYA2buO 0maA== X-Gm-Message-State: AOJu0Yz8T6Q61VE+XBc3fotVElZB/8Hfyq6i8ZpHzw6rU8AaSDJJ/ybR w8N3MJVAWNTFQV5SGyV+kBGpdG6E4Rf/QxMlnUahkgMQ2AGoq+hz X-Received: by 2002:a17:903:2452:b0:1d7:8570:e53 with SMTP id l18-20020a170903245200b001d785700e53mr8332pls.38.1706118439847; Wed, 24 Jan 2024 09:47:19 -0800 (PST) Received: from localhost ([2601:644:9380:8cd0::7fb4]) by smtp.gmail.com with ESMTPSA id d4-20020a170902c18400b001d71649bf9asm9415460pld.252.2024.01.24.09.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:47:19 -0800 (PST) From: Matthew Wood To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner Cc: leitao@debian.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v1 3/8] net: netconsole: move newline trimming to function Date: Wed, 24 Jan 2024 09:47:01 -0800 Message-ID: <20240124174711.1906102-4-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124174711.1906102-1-thepacketgeek@gmail.com> References: <20240124174711.1906102-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 I was unable to find another useable version of this functionality that wasn't private to another driver (E.g. tools/testing/selftests/pidfd/pidfd_fdinfo_test.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 5e720bcf7102..586945e62210 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