Re: [net-next] [v3] net: sfc: avoid format string warning
From: Breno Leitao
Date: Tue Jun 02 2026 - 10:49:15 EST
On Tue, Jun 02, 2026 at 03:53:04PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> Three sfc drivers contain the same *_fill_test() function that takes
> a format string argument that gets passed down to snprintf(), producing
> a warning with clang-22:
>
> drivers/net/ethernet/sfc/falcon/ethtool.c:227:60: error: diagnostic behavior may be improved by adding
> the 'format(printf, 7, 8)' attribute to the declaration of 'ef4_fill_test' [-Werror,-Wmissing-format-attribute]
> 210 | snprintf(test_str, sizeof(test_str), test_format, test_id);
> | ^
> drivers/net/ethernet/sfc/falcon/ethtool.c:210:13: note: 'ef4_fill_test' declared here
>
> Rework these to take a varargs based test_format that allows better
> type checking and a non-varargs unit name that gets pre-filled by
> the caller, so that the compiler can validate all format strings.
>
> Fixes: 3273c2e8c66a ("[netdrvr] sfc: sfc: Add self-test support")
> Link: https://lore.kernel.org/all/20260325134557.3406655-1-arnd@xxxxxxxxxx/
> Reviewed-by: Edward Cree <ecree.xilinx@xxxxxxxxx>
> Cc: Breno Leitao <leitao@xxxxxxxxxx>
> Cc: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
Reviewed-by: Breno Leitao <leitao@xxxxxxxxxx>
> diff --git a/drivers/net/ethernet/sfc/siena/ethtool_common.c b/drivers/net/ethernet/sfc/siena/ethtool_common.c
> index 76cbce2b9592..9df08f1e2347 100644
> --- a/drivers/net/ethernet/sfc/siena/ethtool_common.c
> +++ b/drivers/net/ethernet/sfc/siena/ethtool_common.c
> @@ -199,18 +199,17 @@ int efx_siena_ethtool_set_pauseparam(struct net_device *net_dev,
> * @strings: Ethtool strings, or %NULL
> * @data: Ethtool test results, or %NULL
> * @test: Pointer to test result (used only if data != %NULL)
> - * @unit_format: Unit name format (e.g. "chan\%d")
> - * @unit_id: Unit id (e.g. 0 for "chan0")
> + * @unit_name: Unit name
> * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
> - * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
> *
> * Fill in an individual self-test entry.
> */
> -static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
> - int *test, const char *unit_format, int unit_id,
> - const char *test_format, const char *test_id)
> +static void __printf(6, 7) efx_fill_test(unsigned int test_index, u8 *strings,
> + u64 *data, int *test,
> + const char *unit_name,
> + char *test_format, ...)
Should you keep the 'const' in test_format?