From nobody Thu Nov 14 05:14:06 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD48CC25B48 for ; Thu, 26 Oct 2023 21:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232355AbjJZV40 (ORCPT ); Thu, 26 Oct 2023 17:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231977AbjJZV4U (ORCPT ); Thu, 26 Oct 2023 17:56:20 -0400 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 913CE1B2 for ; Thu, 26 Oct 2023 14:56:15 -0700 (PDT) Received: by mail-oi1-x24a.google.com with SMTP id 5614622812f47-3b2e7ae47d1so2122896b6e.0 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=nEHHRft6MscZpBCpFisGe19KRRUkQ33MSXxkuXqmbAPZTDXRbrxUciuSyP9AK1FJza mkqpT8rlAX1uq+q4VOqoppB2fEtA1b4YZMW4Q+PVXiI4He9hSIOgA9wxGf81bTWQurB8 0B4Qw070hq8wk6MdO8oggjNVpmFwjHZwzy5ynE1UGfIUu0/nagL/ERX2r29DxezB3C9Y 89CjDaI9HhUNmFgDTzuu4m3WJq5yGGH2WO00m/1bAsMNDMMhx46BZqCsVYkVclF5GmdT DWclecXrd5Ktmr0LDCFqQoWLuc9EjYo3JqKnLnwHiJ/+pH3dGkjEPos5VZwvh3+d7+wR nIZA== X-Gm-Message-State: AOJu0YwDlVnDdNMItCHR2aDhoHwQLEanJI4pUcIRTZE+sFY5riSyUFvs MTYPn1mjG/qZK6dVsHPS9njBsUm3IerLIl48JA== 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> 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?q?Ar=C4=B1n=C3=A7_=C3=9CNAL?=" , 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 Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable 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(u= 32 val_min, u32 *val_add, */ extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...= ); =20 +/** + * 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); =20 - const u32 *cap_arr; - u32 arr_size; + const u32 *cap_arr; + u32 arr_size; }; =20 -#define ETHTOOL_FORCED_SPEED_MAP(prefix, value) \ -{ \ - .speed =3D SPEED_##value, \ - .cap_arr =3D prefix##_##value, \ - .arr_size =3D ARRAY_SIZE(prefix##_##value), \ -} +#define ETHTOOL_FORCED_SPEED_MAP(prefix, value) \ + { \ + .speed =3D SPEED_##value, .cap_arr =3D prefix##_##value, \ + .arr_size =3D ARRAY_SIZE(prefix##_##value), \ + } =20 -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); =20 +void ethtool_puts(u8 **data, const char *str) +{ + strscpy(*data, str, ETH_GSTRING_LEN); + *data +=3D ETH_GSTRING_LEN; +} +EXPORT_SYMBOL(ethtool_puts); + static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) { struct ethtool_value id; --=20 2.42.0.820.g83a721a137-goog