diff mbox series

[net,v2,1/2] net: phy: Fix formatting specifier to avoid potential string cuts

Message ID 20250319105813.3102076-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series net: phy: Fix potential string cut when using PHY_ID_FMT | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success Errors and warnings before: 26 (+0) this patch: 26 (+0)
netdev/cc_maintainers warning 1 maintainers not CCed: andrew@lunn.ch
netdev/build_clang fail Errors and warnings before: 10 this patch: 12
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 362 this patch: 362
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 30 this patch: 30
netdev/source_inline success Was 0 now: 0

Commit Message

Andy Shevchenko March 19, 2025, 10:54 a.m. UTC
The PHY_ID_FMT is defined with '%02x' which is _minumum_ digits
to be printed. This, in particular, may trigger GCC warning, when
the parameter for the above mentioned specifier is bigger than
a byte. Avoid this, by limiting the amount of digits to be printed
to two. This is okay as the PHY maximum address is 31 and it fits.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/phy.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko March 19, 2025, 11:21 a.m. UTC | #1
On Wed, Mar 19, 2025 at 12:54:33PM +0200, Andy Shevchenko wrote:
> The PHY_ID_FMT is defined with '%02x' which is _minumum_ digits
> to be printed. This, in particular, may trigger GCC warning, when
> the parameter for the above mentioned specifier is bigger than
> a byte. Avoid this, by limiting the amount of digits to be printed
> to two. This is okay as the PHY maximum address is 31 and it fits.

For the curious: additional reading in the commit
46d57a7a8e33 ("docs: printk-formats: Fix hex printing of signed values").
diff mbox series

Patch

diff --git a/include/linux/phy.h b/include/linux/phy.h
index 19f076a71f94..3b18c241f33e 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -309,7 +309,7 @@  static inline long rgmii_clock(int speed)
 #define PHY_MAX_ADDR	32
 
 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
-#define PHY_ID_FMT "%s:%02x"
+#define PHY_ID_FMT "%s:%02hhx"
 
 #define MII_BUS_ID_SIZE	61