Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: sfc: use ethtool string helpers

The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Edward Cree <ecree.xilinx@gmail.com>
Link: https://patch.msgid.link/20241105231855.235894-1-rosenp@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Rosen Penev and committed by
Jakub Kicinski
9dae5921 7d28f4fc

+83 -106
+1 -1
drivers/net/ethernet/sfc/ef10.c
··· 1751 1751 #endif 1752 1752 } 1753 1753 1754 - static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) 1754 + static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 **names) 1755 1755 { 1756 1756 DECLARE_BITMAP(mask, EF10_STAT_COUNT); 1757 1757
+1 -1
drivers/net/ethernet/sfc/ef100_nic.c
··· 583 583 EFX_GENERIC_SW_STAT(rx_noskb_drops), 584 584 }; 585 585 586 - static size_t ef100_describe_stats(struct efx_nic *efx, u8 *names) 586 + static size_t ef100_describe_stats(struct efx_nic *efx, u8 **names) 587 587 { 588 588 DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {}; 589 589
+20 -26
drivers/net/ethernet/sfc/ethtool_common.c
··· 395 395 return n; 396 396 } 397 397 398 - static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) 398 + static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 **strings) 399 399 { 400 400 size_t n_stats = 0; 401 401 struct efx_channel *channel; ··· 403 403 efx_for_each_channel(channel, efx) { 404 404 if (efx_channel_has_tx_queues(channel)) { 405 405 n_stats++; 406 - if (strings != NULL) { 407 - snprintf(strings, ETH_GSTRING_LEN, 408 - "tx-%u.tx_packets", 409 - channel->tx_queue[0].queue / 410 - EFX_MAX_TXQ_PER_CHANNEL); 406 + if (!strings) 407 + continue; 411 408 412 - strings += ETH_GSTRING_LEN; 413 - } 409 + ethtool_sprintf(strings, "tx-%u.tx_packets", 410 + channel->tx_queue[0].queue / 411 + EFX_MAX_TXQ_PER_CHANNEL); 414 412 } 415 413 } 416 414 efx_for_each_channel(channel, efx) { 417 415 if (efx_channel_has_rx_queue(channel)) { 418 416 n_stats++; 419 - if (strings != NULL) { 420 - snprintf(strings, ETH_GSTRING_LEN, 421 - "rx-%d.rx_packets", channel->channel); 422 - strings += ETH_GSTRING_LEN; 423 - } 417 + if (!strings) 418 + continue; 419 + 420 + ethtool_sprintf(strings, "rx-%d.rx_packets", 421 + channel->channel); 424 422 } 425 423 } 426 424 if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { ··· 426 428 427 429 for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { 428 430 n_stats++; 429 - if (strings) { 430 - snprintf(strings, ETH_GSTRING_LEN, 431 - "tx-xdp-cpu-%hu.tx_packets", xdp); 432 - strings += ETH_GSTRING_LEN; 433 - } 431 + if (!strings) 432 + continue; 433 + 434 + ethtool_sprintf(strings, "tx-xdp-cpu-%hu.tx_packets", 435 + xdp); 434 436 } 435 437 } 436 438 ··· 462 464 463 465 switch (string_set) { 464 466 case ETH_SS_STATS: 465 - strings += (efx->type->describe_stats(efx, strings) * 466 - ETH_GSTRING_LEN); 467 + efx->type->describe_stats(efx, &strings); 467 468 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) 468 - strscpy(strings + i * ETH_GSTRING_LEN, 469 - efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); 470 - strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; 471 - strings += (efx_describe_per_queue_stats(efx, strings) * 472 - ETH_GSTRING_LEN); 473 - efx_ptp_describe_stats(efx, strings); 469 + ethtool_puts(&strings, efx_sw_stat_desc[i].name); 470 + efx_describe_per_queue_stats(efx, &strings); 471 + efx_ptp_describe_stats(efx, &strings); 474 472 break; 475 473 case ETH_SS_TEST: 476 474 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
+14 -20
drivers/net/ethernet/sfc/falcon/ethtool.c
··· 353 353 return n; 354 354 } 355 355 356 - static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings) 356 + static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 **strings) 357 357 { 358 358 size_t n_stats = 0; 359 359 struct ef4_channel *channel; ··· 361 361 ef4_for_each_channel(channel, efx) { 362 362 if (ef4_channel_has_tx_queues(channel)) { 363 363 n_stats++; 364 - if (strings != NULL) { 365 - snprintf(strings, ETH_GSTRING_LEN, 366 - "tx-%u.tx_packets", 367 - channel->tx_queue[0].queue / 368 - EF4_TXQ_TYPES); 364 + if (!strings) 365 + continue; 369 366 370 - strings += ETH_GSTRING_LEN; 371 - } 367 + ethtool_sprintf(strings, "tx-%u.tx_packets", 368 + channel->tx_queue[0].queue / 369 + EF4_TXQ_TYPES); 372 370 } 373 371 } 374 372 ef4_for_each_channel(channel, efx) { 375 373 if (ef4_channel_has_rx_queue(channel)) { 376 374 n_stats++; 377 - if (strings != NULL) { 378 - snprintf(strings, ETH_GSTRING_LEN, 379 - "rx-%d.rx_packets", channel->channel); 380 - strings += ETH_GSTRING_LEN; 381 - } 375 + if (!strings) 376 + continue; 377 + 378 + ethtool_sprintf(strings, "rx-%d.rx_packets", 379 + channel->channel); 382 380 } 383 381 } 384 382 return n_stats; ··· 407 409 408 410 switch (string_set) { 409 411 case ETH_SS_STATS: 410 - strings += (efx->type->describe_stats(efx, strings) * 411 - ETH_GSTRING_LEN); 412 + efx->type->describe_stats(efx, &strings); 412 413 for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++) 413 - strscpy(strings + i * ETH_GSTRING_LEN, 414 - ef4_sw_stat_desc[i].name, ETH_GSTRING_LEN); 415 - strings += EF4_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; 416 - strings += (ef4_describe_per_queue_stats(efx, strings) * 417 - ETH_GSTRING_LEN); 414 + ethtool_puts(&strings, ef4_sw_stat_desc[i].name); 415 + ef4_describe_per_queue_stats(efx, &strings); 418 416 break; 419 417 case ETH_SS_TEST: 420 418 ef4_ethtool_fill_self_tests(efx, NULL, strings, NULL);
+1 -1
drivers/net/ethernet/sfc/falcon/falcon.c
··· 2564 2564 efx->nic_data = NULL; 2565 2565 } 2566 2566 2567 - static size_t falcon_describe_nic_stats(struct ef4_nic *efx, u8 *names) 2567 + static size_t falcon_describe_nic_stats(struct ef4_nic *efx, u8 **names) 2568 2568 { 2569 2569 return ef4_nic_describe_stats(falcon_stat_desc, FALCON_STAT_COUNT, 2570 2570 falcon_stat_mask, names);
+1 -1
drivers/net/ethernet/sfc/falcon/net_driver.h
··· 1057 1057 void (*finish_flush)(struct ef4_nic *efx); 1058 1058 void (*prepare_flr)(struct ef4_nic *efx); 1059 1059 void (*finish_flr)(struct ef4_nic *efx); 1060 - size_t (*describe_stats)(struct ef4_nic *efx, u8 *names); 1060 + size_t (*describe_stats)(struct ef4_nic *efx, u8 **names); 1061 1061 size_t (*update_stats)(struct ef4_nic *efx, u64 *full_stats, 1062 1062 struct rtnl_link_stats64 *core_stats); 1063 1063 void (*start_stats)(struct ef4_nic *efx);
+3 -6
drivers/net/ethernet/sfc/falcon/nic.c
··· 444 444 * bits in the first @count bits of @mask for which a name is defined. 445 445 */ 446 446 size_t ef4_nic_describe_stats(const struct ef4_hw_stat_desc *desc, size_t count, 447 - const unsigned long *mask, u8 *names) 447 + const unsigned long *mask, u8 **names) 448 448 { 449 449 size_t visible = 0; 450 450 size_t index; 451 451 452 452 for_each_set_bit(index, mask, count) { 453 453 if (desc[index].name) { 454 - if (names) { 455 - strscpy(names, desc[index].name, 456 - ETH_GSTRING_LEN); 457 - names += ETH_GSTRING_LEN; 458 - } 454 + if (names) 455 + ethtool_puts(names, desc[index].name); 459 456 ++visible; 460 457 } 461 458 }
+1 -1
drivers/net/ethernet/sfc/falcon/nic.h
··· 497 497 void ef4_nic_get_regs(struct ef4_nic *efx, void *buf); 498 498 499 499 size_t ef4_nic_describe_stats(const struct ef4_hw_stat_desc *desc, size_t count, 500 - const unsigned long *mask, u8 *names); 500 + const unsigned long *mask, u8 **names); 501 501 void ef4_nic_update_stats(const struct ef4_hw_stat_desc *desc, size_t count, 502 502 const unsigned long *mask, u64 *stats, 503 503 const void *dma_buf, bool accumulate);
+1 -1
drivers/net/ethernet/sfc/net_driver.h
··· 1408 1408 int (*fini_dmaq)(struct efx_nic *efx); 1409 1409 void (*prepare_flr)(struct efx_nic *efx); 1410 1410 void (*finish_flr)(struct efx_nic *efx); 1411 - size_t (*describe_stats)(struct efx_nic *efx, u8 *names); 1411 + size_t (*describe_stats)(struct efx_nic *efx, u8 **names); 1412 1412 size_t (*update_stats)(struct efx_nic *efx, u64 *full_stats, 1413 1413 struct rtnl_link_stats64 *core_stats); 1414 1414 size_t (*update_stats_atomic)(struct efx_nic *efx, u64 *full_stats,
+3 -6
drivers/net/ethernet/sfc/nic.c
··· 299 299 * bits in the first @count bits of @mask for which a name is defined. 300 300 */ 301 301 size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count, 302 - const unsigned long *mask, u8 *names) 302 + const unsigned long *mask, u8 **names) 303 303 { 304 304 size_t visible = 0; 305 305 size_t index; 306 306 307 307 for_each_set_bit(index, mask, count) { 308 308 if (desc[index].name) { 309 - if (names) { 310 - strscpy(names, desc[index].name, 311 - ETH_GSTRING_LEN); 312 - names += ETH_GSTRING_LEN; 313 - } 309 + if (names) 310 + ethtool_puts(names, desc[index].name); 314 311 ++visible; 315 312 } 316 313 }
+1 -1
drivers/net/ethernet/sfc/nic_common.h
··· 241 241 #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1)) 242 242 243 243 size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count, 244 - const unsigned long *mask, u8 *names); 244 + const unsigned long *mask, u8 **names); 245 245 int efx_nic_copy_stats(struct efx_nic *efx, __le64 *dest); 246 246 void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count, 247 247 const unsigned long *mask, u64 *stats,
+1 -1
drivers/net/ethernet/sfc/ptp.c
··· 399 399 [0 ... BITS_TO_LONGS(PTP_STAT_COUNT) - 1] = ~0UL, 400 400 }; 401 401 402 - size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings) 402 + size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 **strings) 403 403 { 404 404 if (!efx->ptp_data) 405 405 return 0;
+1 -1
drivers/net/ethernet/sfc/ptp.h
··· 30 30 unsigned int new_mode); 31 31 int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); 32 32 void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev); 33 - size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings); 33 + size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 **strings); 34 34 size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats); 35 35 void efx_time_sync_event(struct efx_channel *channel, efx_qword_t *ev); 36 36 void __efx_rx_skb_attach_timestamp(struct efx_channel *channel,
+20 -26
drivers/net/ethernet/sfc/siena/ethtool_common.c
··· 395 395 test->flags |= ETH_TEST_FL_FAILED; 396 396 } 397 397 398 - static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) 398 + static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 **strings) 399 399 { 400 400 size_t n_stats = 0; 401 401 struct efx_channel *channel; ··· 403 403 efx_for_each_channel(channel, efx) { 404 404 if (efx_channel_has_tx_queues(channel)) { 405 405 n_stats++; 406 - if (strings != NULL) { 407 - snprintf(strings, ETH_GSTRING_LEN, 408 - "tx-%u.tx_packets", 409 - channel->tx_queue[0].queue / 410 - EFX_MAX_TXQ_PER_CHANNEL); 406 + if (!strings) 407 + continue; 411 408 412 - strings += ETH_GSTRING_LEN; 413 - } 409 + ethtool_sprintf(strings, "tx-%u.tx_packets", 410 + channel->tx_queue[0].queue / 411 + EFX_MAX_TXQ_PER_CHANNEL); 414 412 } 415 413 } 416 414 efx_for_each_channel(channel, efx) { 417 415 if (efx_channel_has_rx_queue(channel)) { 418 416 n_stats++; 419 - if (strings != NULL) { 420 - snprintf(strings, ETH_GSTRING_LEN, 421 - "rx-%d.rx_packets", channel->channel); 422 - strings += ETH_GSTRING_LEN; 423 - } 417 + if (!strings) 418 + continue; 419 + 420 + ethtool_sprintf(strings, "rx-%d.rx_packets", 421 + channel->channel); 424 422 } 425 423 } 426 424 if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { ··· 426 428 427 429 for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { 428 430 n_stats++; 429 - if (strings) { 430 - snprintf(strings, ETH_GSTRING_LEN, 431 - "tx-xdp-cpu-%hu.tx_packets", xdp); 432 - strings += ETH_GSTRING_LEN; 433 - } 431 + if (!strings) 432 + continue; 433 + 434 + ethtool_sprintf(strings, "tx-xdp-cpu-%hu.tx_packets", 435 + xdp); 434 436 } 435 437 } 436 438 ··· 462 464 463 465 switch (string_set) { 464 466 case ETH_SS_STATS: 465 - strings += (efx->type->describe_stats(efx, strings) * 466 - ETH_GSTRING_LEN); 467 + efx->type->describe_stats(efx, &strings); 467 468 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) 468 - strscpy(strings + i * ETH_GSTRING_LEN, 469 - efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); 470 - strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; 471 - strings += (efx_describe_per_queue_stats(efx, strings) * 472 - ETH_GSTRING_LEN); 473 - efx_siena_ptp_describe_stats(efx, strings); 469 + ethtool_puts(&strings, efx_sw_stat_desc[i].name); 470 + efx_describe_per_queue_stats(efx, &strings); 471 + efx_siena_ptp_describe_stats(efx, &strings); 474 472 break; 475 473 case ETH_SS_TEST: 476 474 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
+1 -1
drivers/net/ethernet/sfc/siena/net_driver.h
··· 1307 1307 void (*finish_flush)(struct efx_nic *efx); 1308 1308 void (*prepare_flr)(struct efx_nic *efx); 1309 1309 void (*finish_flr)(struct efx_nic *efx); 1310 - size_t (*describe_stats)(struct efx_nic *efx, u8 *names); 1310 + size_t (*describe_stats)(struct efx_nic *efx, u8 **names); 1311 1311 size_t (*update_stats)(struct efx_nic *efx, u64 *full_stats, 1312 1312 struct rtnl_link_stats64 *core_stats); 1313 1313 size_t (*update_stats_atomic)(struct efx_nic *efx, u64 *full_stats,
+7 -7
drivers/net/ethernet/sfc/siena/nic.c
··· 449 449 * Returns the number of visible statistics, i.e. the number of set 450 450 * bits in the first @count bits of @mask for which a name is defined. 451 451 */ 452 - size_t efx_siena_describe_stats(const struct efx_hw_stat_desc *desc, size_t count, 453 - const unsigned long *mask, u8 *names) 452 + size_t efx_siena_describe_stats(const struct efx_hw_stat_desc *desc, 453 + size_t count, const unsigned long *mask, 454 + u8 **names) 454 455 { 455 456 size_t visible = 0; 456 457 size_t index; 457 458 458 459 for_each_set_bit(index, mask, count) { 459 460 if (desc[index].name) { 460 - if (names) { 461 - strscpy(names, desc[index].name, 462 - ETH_GSTRING_LEN); 463 - names += ETH_GSTRING_LEN; 464 - } 465 461 ++visible; 462 + if (!names) 463 + continue; 464 + 465 + ethtool_puts(names, desc[index].name); 466 466 } 467 467 } 468 468
+3 -2
drivers/net/ethernet/sfc/siena/nic_common.h
··· 239 239 240 240 #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1)) 241 241 242 - size_t efx_siena_describe_stats(const struct efx_hw_stat_desc *desc, size_t count, 243 - const unsigned long *mask, u8 *names); 242 + size_t efx_siena_describe_stats(const struct efx_hw_stat_desc *desc, 243 + size_t count, const unsigned long *mask, 244 + u8 **names); 244 245 void efx_siena_update_stats(const struct efx_hw_stat_desc *desc, size_t count, 245 246 const unsigned long *mask, u64 *stats, 246 247 const void *dma_buf, bool accumulate);
+1 -1
drivers/net/ethernet/sfc/siena/ptp.c
··· 393 393 [0 ... BITS_TO_LONGS(PTP_STAT_COUNT) - 1] = ~0UL, 394 394 }; 395 395 396 - size_t efx_siena_ptp_describe_stats(struct efx_nic *efx, u8 *strings) 396 + size_t efx_siena_ptp_describe_stats(struct efx_nic *efx, u8 **strings) 397 397 { 398 398 if (!efx->ptp_data) 399 399 return 0;
+1 -1
drivers/net/ethernet/sfc/siena/ptp.h
··· 28 28 unsigned int new_mode); 29 29 int efx_siena_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); 30 30 void efx_siena_ptp_event(struct efx_nic *efx, efx_qword_t *ev); 31 - size_t efx_siena_ptp_describe_stats(struct efx_nic *efx, u8 *strings); 31 + size_t efx_siena_ptp_describe_stats(struct efx_nic *efx, u8 **strings); 32 32 size_t efx_siena_ptp_update_stats(struct efx_nic *efx, u64 *stats); 33 33 void efx_siena_time_sync_event(struct efx_channel *channel, efx_qword_t *ev); 34 34 void __efx_siena_rx_skb_attach_timestamp(struct efx_channel *channel,
+1 -1
drivers/net/ethernet/sfc/siena/siena.c
··· 545 545 [0 ... BITS_TO_LONGS(SIENA_STAT_COUNT) - 1] = ~0UL, 546 546 }; 547 547 548 - static size_t siena_describe_nic_stats(struct efx_nic *efx, u8 *names) 548 + static size_t siena_describe_nic_stats(struct efx_nic *efx, u8 **names) 549 549 { 550 550 return efx_siena_describe_stats(siena_stat_desc, SIENA_STAT_COUNT, 551 551 siena_stat_mask, names);