diff mbox series

[net,v3,1/2] net: phy: Introduce PHY_ID_SIZE — minimum size for PHY ID string

Message ID 20250324144751.1271761-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New
Headers show
Series net: usb: asix: ax88772: Fix potential string cut | expand

Commit Message

Andy Shevchenko March 24, 2025, 2:39 p.m. UTC
The PHY_ID_FMT defines the format specifier "%s:%02x" to form
the PHY ID string, where the maximum of the first part is defined
in MII_BUS_ID_SIZE, including NUL terminator, and the second part
is implied to be 3 as the maximum address is limited to 32, meaning
that 2 hex digits is more than enough, plus ':' (colon) delimiter.
However, some drivers, which are using PHY_ID_FMT, customise buffer
size and do that incorrectly. Introduce a new constant PHY_ID_SIZE
that makes the minimum required size explicit, so drivers are
encouraged to use it.

Suggested-by: "Russell King (Oracle)" <linux@armlinux.org.uk>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/phy.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Russell King (Oracle) March 24, 2025, 3:06 p.m. UTC | #1
On Mon, Mar 24, 2025 at 04:39:29PM +0200, Andy Shevchenko wrote:
> The PHY_ID_FMT defines the format specifier "%s:%02x" to form
> the PHY ID string, where the maximum of the first part is defined
> in MII_BUS_ID_SIZE, including NUL terminator, and the second part
> is implied to be 3 as the maximum address is limited to 32, meaning
> that 2 hex digits is more than enough, plus ':' (colon) delimiter.
> However, some drivers, which are using PHY_ID_FMT, customise buffer
> size and do that incorrectly. Introduce a new constant PHY_ID_SIZE
> that makes the minimum required size explicit, so drivers are
> encouraged to use it.
> 
> Suggested-by: "Russell King (Oracle)" <linux@armlinux.org.uk>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!
Andy Shevchenko March 24, 2025, 3:57 p.m. UTC | #2
On Mon, Mar 24, 2025 at 03:06:22PM +0000, Russell King (Oracle) wrote:
> On Mon, Mar 24, 2025 at 04:39:29PM +0200, Andy Shevchenko wrote:
> > The PHY_ID_FMT defines the format specifier "%s:%02x" to form
> > the PHY ID string, where the maximum of the first part is defined
> > in MII_BUS_ID_SIZE, including NUL terminator, and the second part
> > is implied to be 3 as the maximum address is limited to 32, meaning
> > that 2 hex digits is more than enough, plus ':' (colon) delimiter.
> > However, some drivers, which are using PHY_ID_FMT, customise buffer
> > size and do that incorrectly. Introduce a new constant PHY_ID_SIZE
> > that makes the minimum required size explicit, so drivers are
> > encouraged to use it.
> > 
> > Suggested-by: "Russell King (Oracle)" <linux@armlinux.org.uk>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> 
> Thanks!

Thank you!

And just a bit of offtopic, can you look at
20250312194921.103004-1-andriy.shevchenko@linux.intel.com
and comment / apply?

That is one of the only few obstacles for me (and perhaps others, like CIs)
to enable CONFIG_WERROR when build with `make W=1` (implying existing defconfigs
for x86).
Russell King (Oracle) March 24, 2025, 5:38 p.m. UTC | #3
On Mon, Mar 24, 2025 at 05:57:02PM +0200, Andy Shevchenko wrote:
> On Mon, Mar 24, 2025 at 03:06:22PM +0000, Russell King (Oracle) wrote:
> > On Mon, Mar 24, 2025 at 04:39:29PM +0200, Andy Shevchenko wrote:
> > > The PHY_ID_FMT defines the format specifier "%s:%02x" to form
> > > the PHY ID string, where the maximum of the first part is defined
> > > in MII_BUS_ID_SIZE, including NUL terminator, and the second part
> > > is implied to be 3 as the maximum address is limited to 32, meaning
> > > that 2 hex digits is more than enough, plus ':' (colon) delimiter.
> > > However, some drivers, which are using PHY_ID_FMT, customise buffer
> > > size and do that incorrectly. Introduce a new constant PHY_ID_SIZE
> > > that makes the minimum required size explicit, so drivers are
> > > encouraged to use it.
> > > 
> > > Suggested-by: "Russell King (Oracle)" <linux@armlinux.org.uk>
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> > 
> > Thanks!
> 
> Thank you!
> 
> And just a bit of offtopic, can you look at
> 20250312194921.103004-1-andriy.shevchenko@linux.intel.com
> and comment / apply?

That needs to go into my patch system please. Thanks.
Andy Shevchenko March 24, 2025, 7:52 p.m. UTC | #4
On Mon, Mar 24, 2025 at 05:38:15PM +0000, Russell King (Oracle) wrote:
> On Mon, Mar 24, 2025 at 05:57:02PM +0200, Andy Shevchenko wrote:
> > On Mon, Mar 24, 2025 at 03:06:22PM +0000, Russell King (Oracle) wrote:

...

> > And just a bit of offtopic, can you look at
> > 20250312194921.103004-1-andriy.shevchenko@linux.intel.com
> > and comment / apply?
> 
> That needs to go into my patch system please. Thanks.

Ah, cool, just made it to appear there.
diff mbox series

Patch

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