From patchwork Thu Oct 26 21:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13437971 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82D8C3E47E for ; Thu, 26 Oct 2023 21:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YPj55n2C" Received: from mail-oi1-x24a.google.com (mail-oi1-x24a.google.com [IPv6:2607:f8b0:4864:20::24a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90B4E1AD for ; Thu, 26 Oct 2023 14:56:15 -0700 (PDT) Received: by mail-oi1-x24a.google.com with SMTP id 5614622812f47-3b2ef9e4c25so2108234b6e.1 for ; Thu, 26 Oct 2023 14:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698357375; x=1698962175; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BGnfO5yo1brrl3JG1fuz3XeacVop9nGYIXct/GsCbHA=; b=YPj55n2CVrwECELqBp1BWiRdDeiahWrh09vlZ9y4NuNIM4rkt4JjSTqAD3G14/dtDN s9qy7TH1VNXFRWZRxvyV8chlR75DGWEb8DHwpyan3CMTpFapkWaO+0Vdbwaff7HzQotA 2wsba9jbSdhe9m3ytUGelfD2m5nszW3EMaTmjhwE7kjyctQaGJ6wSpPY1JBk/8mOG4IK e0Lfr3qz3Krsqf3x0jI5dko8CEbdQ2TdfXUaIyhK86nUQpuN36EuhYopTbPE+gGu2CYu kqY2vs8KI8byVCUOC064QBGruHUGWvdsrbkg7r9XFBZpMXhKyWNgBjL0Pb4SEaK2emWS v6SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698357375; x=1698962175; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BGnfO5yo1brrl3JG1fuz3XeacVop9nGYIXct/GsCbHA=; b=vlGGkEQPMtQd70aQpnERO4aWtbbEz90Erv8/lNngPiyw2E+ZI7Cph1FuHciuOnS6cj 2+Q7T2yVgKoJypOjzjPgJm1qeJ5dm3SWxqrrwIZMV82aqCR9nrCJwDq/ROwJvreRx5vU mgv7KWyFnFfhbKow2gvIOzFepqmpFWhYObUHa5XsmvrGIBioJpSO+PDkc2+qoycxll4C IGIlFKo2gzloHLmLStzzh6vc4ihjTaE5hLJzL6mi6TDhUC/JYF7XQ08JTcEy98BdRIel +9gstvZslyaz1QfILHfb7ge7Kd15v/G83cQDxo2ITwnbaIT1Y/mVO3Rk7zM99RDqXA2I NdUA== X-Gm-Message-State: AOJu0Yz8jOBba4Q1SRc5xrDh7aG/tuFeTvYLMHo7DT8yd4K4PfO0aSU6 Ugxebt1m4fp5epYRmSu+geM7kFPh2d/WVm6Bqg== X-Google-Smtp-Source: AGHT+IF5gOPekjq4+QDN3pBVLuKGKeKe6H18GFsh2OoUyXeyiM7MMvJg4zKShMICsysc3GRHujvfELlFaE0x7zGmTQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6808:f01:b0:3ad:f860:b315 with SMTP id m1-20020a0568080f0100b003adf860b315mr220107oiw.2.1698357374848; Thu, 26 Oct 2023 14:56:14 -0700 (PDT) Date: Thu, 26 Oct 2023 21:56:07 +0000 In-Reply-To: <20231026-ethtool_puts_impl-v2-0-0d67cbdd0538@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231026-ethtool_puts_impl-v2-0-0d67cbdd0538@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698357372; l=2655; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=8djdPmMRDp1kcBXDhs8ygPXLuTfgtvGs7Yo95u6cw0k=; b=oxdmPg9KABeZlWyohpoRER6suttzISQsU1pFrM2utjhSx+ViWnRXf8IVNcElP/r+ITJcWQj9E seeyc13ojC5BXu0aQZG5KcerhesMEYloY+EmDxWK7pulBdKUNUGMRBN X-Mailer: b4 0.12.3 Message-ID: <20231026-ethtool_puts_impl-v2-1-0d67cbdd0538@google.com> Subject: [PATCH next v2 1/3] ethtool: Implement ethtool_puts() From: Justin Stitt To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shay Agroskin , Arthur Kiyanovski , David Arinzon , Noam Dagan , Saeed Bishara , Rasesh Mody , Sudarsana Kalluru , GR-Linux-NIC-Dev@marvell.com, Dimitris Michailidis , Yisen Zhuang , Salil Mehta , Jesse Brandeburg , Tony Nguyen , Louis Peens , Shannon Nelson , Brett Creeley , drivers@pensando.io, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Ronak Doshi , VMware PV-Drivers Reviewers , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Hauke Mehrtens , Andrew Lunn , Florian Fainelli , Vladimir Oltean , " =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= " , Daniel Golle , Landen Chao , DENG Qingfang , Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno , Linus Walleij , " =?utf-8?q?Alvin_=C5=A0ipraga?= " , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Lars Povlsen , Steen Hegelund , Daniel Machon , UNGLinuxDriver@microchip.com, Jiawen Wu , Mengyuan Lou , Heiner Kallweit , Russell King , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Nick Desaulniers , Nathan Chancellor , Kees Cook , intel-wired-lan@lists.osuosl.org, oss-drivers@corigine.com, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, bpf@vger.kernel.org, Justin Stitt X-Patchwork-Delegate: kuba@kernel.org Use strscpy() to implement ethtool_puts(). Functionally the same as ethtool_sprintf() when it's used with two arguments or with just "%s" format specifier. Signed-off-by: Justin Stitt --- include/linux/ethtool.h | 34 +++++++++++++++++++++++----------- net/ethtool/ioctl.c | 7 +++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 226a36ed5aa1..7129dd2e227c 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1053,22 +1053,34 @@ static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add, */ extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...); +/** + * ethtool_puts - Write string to ethtool string data + * @data: Pointer to start of string to update + * @str: String to write + * + * Write string to data. Update data to point at start of next + * string. + * + * Prefer this function to ethtool_sprintf() when given only + * two arguments or if @fmt is just "%s". + */ +extern void ethtool_puts(u8 **data, const char *str); + /* Link mode to forced speed capabilities maps */ struct ethtool_forced_speed_map { - u32 speed; + u32 speed; __ETHTOOL_DECLARE_LINK_MODE_MASK(caps); - const u32 *cap_arr; - u32 arr_size; + const u32 *cap_arr; + u32 arr_size; }; -#define ETHTOOL_FORCED_SPEED_MAP(prefix, value) \ -{ \ - .speed = SPEED_##value, \ - .cap_arr = prefix##_##value, \ - .arr_size = ARRAY_SIZE(prefix##_##value), \ -} +#define ETHTOOL_FORCED_SPEED_MAP(prefix, value) \ + { \ + .speed = SPEED_##value, .cap_arr = prefix##_##value, \ + .arr_size = ARRAY_SIZE(prefix##_##value), \ + } -void -ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size); +void ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, + u32 size); #endif /* _LINUX_ETHTOOL_H */ diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 0b0ce4f81c01..abdf05edf804 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1991,6 +1991,13 @@ __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...) } EXPORT_SYMBOL(ethtool_sprintf); +void ethtool_puts(u8 **data, const char *str) +{ + strscpy(*data, str, ETH_GSTRING_LEN); + *data += ETH_GSTRING_LEN; +} +EXPORT_SYMBOL(ethtool_puts); + static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) { struct ethtool_value id;