driver core: Fix size calculation of symlink name for devlink_(add|remove)_symlinks()
PATCH 1/1 driver core: Fix size calculation of symlink name for devlink_(add|remove)_symlinks()
From: Zijun Hu <[email protected]>
devlink_(add|remove)_symlinks() wants to kzalloc() memory to save symlink name for either supplier or consumer, but forget to consider consumer prefix when calclulate memory size, fixed by considering prefix for both supplier and consumer.
--- drivers/base/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/core.c +2 -2
@@ -572,7 +572,7 @@ static int devlink_add_symlinks(struct device *dev) len =max (strlen (dev_bus_name (sup)) +strlen (dev_name (sup)),strlen (dev_bus_name (con)) +strlen (dev_name (con))); len +=strlen (":" ); - len +=strlen ("supplier:" ) +1 ; + len +=max (strlen ("supplier:" ),strlen ("consumer:" )) +1 ; buf =kzalloc (len,GFP_KERNEL );if (!buf)return -ENOMEM ;
@@ -623,7 +623,7 @@ static void devlink_remove_symlinks(struct device *dev) len =max (strlen (dev_bus_name (sup)) +strlen (dev_name (sup)),strlen (dev_bus_name (con)) +strlen (dev_name (con))); len +=strlen (":" ); - len +=strlen ("supplier:" ) +1 ; + len +=max (strlen ("supplier:" ),strlen ("consumer:" )) +1 ; buf =kzalloc (len,GFP_KERNEL );if (!buf) {WARN (1 ,"Unable to properly free device link symlinks!\n" );
---
base-commit: c6653f49e4fd3b0d52c12a1fc814d6c5b234ea15
change-id: 20240707-devlink_fix-0fa46dedfe95
Best regards,
Signature · 1 line
Zijun Hu <[email protected]>
Saravana Kannan
NAKQuoted 7 lines · Zijun Hu
From: Zijun Hu <[email protected]>
devlink_(add|remove)_symlinks() wants to
kzalloc()memory to save symlink name for either supplier or consumer, but forget to consider consumer prefix when calclulate memory size, fixed by considering prefix for both supplier and consumer.
No, I didn't forget to take "consumer" into account :) Both supplier and consumer are the same length. So I didn't bother doing both. I don't see a point behind this patch.
Quoted 2 lines
Fixes 287905e68dd2 ("driver core: Expose device link details in sysfs")
It's definitely not "Fixing" anything because nothing is broken.
Nack.
If you really want this in, remove this tag and send it again. I won't ack or review it though as I don't think it adds much value. Greg can take it if he thinks he likes it.
-Saravana
Quoted 36 lines
Signed-off-by Zijun Hu <[email protected]>--- drivers/base/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/base/core.c +2
-3@@ -572,7 +572,7 @@ static int devlink_add_symlinks(struct device *dev) len =max (strlen (dev_bus_name (sup)) +strlen (dev_name (sup)),strlen (dev_bus_name (con)) +strlen (dev_name (con))); len +=strlen (":" ); - len +=strlen ("supplier:" ) +1 ; + len +=max (strlen ("supplier:" ),strlen ("consumer:" )) +1 ; buf =kzalloc (len,GFP_KERNEL );if (!buf)return -ENOMEM ;@@ -623,7 +623,7 @@ static void devlink_remove_symlinks(struct device *dev) len =max (strlen (dev_bus_name (sup)) +strlen (dev_name (sup)),strlen (dev_bus_name (con)) +strlen (dev_name (con))); len +=strlen (":" ); - len +=strlen ("supplier:" ) +1 ; + len +=max (strlen ("supplier:" ),strlen ("consumer:" )) +1 ; buf =kzalloc (len,GFP_KERNEL );if (!buf) {WARN (1 ,"Unable to properly free device link symlinks!\n" ); ---base-commit:
c6653f49e4fd3b0d52c12a1fc814d6c5b234ea15
change-id: 20240707-devlink_fix-0fa46dedfe95Best regards,
--
Zijun Hu <[email protected]>
Quoted 4 lines · Saravana Kannan
Quoted 3 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Quoted 9 lines
Quoted 4 lines
devlink_(add|remove)_symlinks() wants to
kzalloc()memory to save symlink name for either supplier or consumer, but forget to consider consumer prefix when calclulate memory size, fixed by considering prefix for both supplier and consumer.No, I didn't forget to take "consumer" into account :) Both supplier and consumer are the same length. So I didn't bother doing both. I don't see a point behind this patch.
it is not obvious for code readers that "supplier:" and "consumer:" have the same string length.
code readers maybe need to count characters one by one for both strings to confirm both have the same length.
Quoted 5 lines
Quoted 2 lines
Fixes 287905e68dd2 ("driver core: Expose device link details in sysfs")It's definitely not "Fixing" anything because nothing is broken. this change maybe fix algorithm or procedures to calculate the size to
kzalloc() even if it don't change the resulted size.
Quoted 5 lines
Nack.
Quoted 1 line
If you really want this in, remove this tag and send it again. I won't
ack or review it though as I don't think it adds much value. Greg can take it if he thinks he likes it.
okay, will send v2 which will remove the fix tag, i feels this change is worthy due to below reasons:
1) readers is easier to understand the algorithm or procedures to calculate the resulted size.
2) readers don't need to take extra effort to confirm that fact that both string have the same length.
let us wait for Greg's opinions.
Quoted 38 lines
-Saravana
Quoted 36 lines
Signed-off-by Zijun Hu <[email protected]>--- drivers/base/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/base/core.c +2
-3@@ -572,7 +572,7 @@ static int devlink_add_symlinks(struct device *dev) len =max (strlen (dev_bus_name (sup)) +strlen (dev_name (sup)),strlen (dev_bus_name (con)) +strlen (dev_name (con))); len +=strlen (":" ); - len +=strlen ("supplier:" ) +1 ; + len +=max (strlen ("supplier:" ),strlen ("consumer:" )) +1 ; buf =kzalloc (len,GFP_KERNEL );if (!buf)return -ENOMEM ;@@ -623,7 +623,7 @@ static void devlink_remove_symlinks(struct device *dev) len =max (strlen (dev_bus_name (sup)) +strlen (dev_name (sup)),strlen (dev_bus_name (con)) +strlen (dev_name (con))); len +=strlen (":" ); - len +=strlen ("supplier:" ) +1 ; + len +=max (strlen ("supplier:" ),strlen ("consumer:" )) +1 ; buf =kzalloc (len,GFP_KERNEL );if (!buf) {WARN (1 ,"Unable to properly free device link symlinks!\n" ); ---base-commit:
c6653f49e4fd3b0d52c12a1fc814d6c5b234ea15
change-id: 20240707-devlink_fix-0fa46dedfe95Best regards,
--
Zijun Hu <[email protected]>