mctp: serial: replace memset with zero-initialization
PATCH v2 1/1 mctp: serial: replace memset with zero-initialization
Use empty brace initialization (= {}) instead of explicit memset() to zero-initialize stack memory to simplify the code.
No functional change.
---
Changes in v2:
- Fixed a compilation error caused by a duplicate variable declaration caught by the kernel test robot.
drivers/net/mctp/mctp-serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/mctp/mctp-serial.c +1 -2
@@ -536,13 +536,12 @@ struct test_chunk_tx {static void test_next_chunk_len (struct kunit *test) { -struct mctp_serial devx; +struct mctp_serial devx = { };struct mctp_serial *dev = &devx;int next;const struct test_chunk_tx *params = test->param_value; -memset (dev,0x0 ,sizeof (*dev));memcpy (dev->txbuf, params->input, params->input_len); dev->txlen = params->input_len;
Signature · 1 line
2.43.0
Quoted 4 lines · On Sat, 30 May 2026 22:46:46 +0000 Manish Baing <[email protected]>…
Use empty brace initialization (= {}) instead of explicit
memset()to zero-initialize stack memory to simplify the code.No functional change.
Isn't it also entirely pointless?
-- David
Quoted 29 lines
Signed-off-by Manish Baing <[email protected]>---
Changes in v2:
- Fixed a compilation error caused by a duplicate variable declaration caught by the kernel test robot.drivers/net/mctp/mctp-serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/mctp/mctp-serial.c +1
-2@@ -536,13 +536,12 @@ struct test_chunk_tx {static void test_next_chunk_len (struct kunit *test) { -struct mctp_serial devx; +struct mctp_serial devx = { };struct mctp_serial *dev = &devx;int next;const struct test_chunk_tx *params = test->param_value; -memset (dev,0x0 ,sizeof (*dev));memcpy (dev->txbuf, params->input, params->input_len); dev->txlen = params->input_len;
Hi David,
I understand that this might just be unnecessary churn for the networking subsystem, and I am perfectly fine dropping the patch if that is the case.
However, for my own learning, I would love to get your perspective on this. I was carrying over a pattern from recent cleanups in the IIO subsystem [1],
as empty brace initialization was noted as the preferred approach in those discussions (including by Kees Cook [2]).
Is the reasoning behind that recommendation just not applicable to netdev,or is the policy here strictly against code churn unless it fixes a tangible bug?
Thanks for the guidance.
[1]: https://lore.kernel.org/all/20250611-iio-zero-init-stack-with-instead-of-memset-v1-0-ebb2d0a24302@baylibre.com/
[2]: https://lore.kernel.org/linux-iio/202505090942.48EBF01B@keescook/
Regards,
Manish
Quoted 43 lines · David Laight
Quoted 4 lines · On Sat, 30 May 2026 22:46:46 +0000 Manish Baing <[email protected]>…
Use empty brace initialization (= {}) instead of explicit
memset()to zero-initialize stack memory to simplify the code.No functional change.
Isn't it also entirely pointless?
-- David
Quoted 29 lines
Signed-off-by Manish Baing <[email protected]>---
Changes in v2:
- Fixed a compilation error caused by a duplicate variable declaration caught by the kernel test robot.drivers/net/mctp/mctp-serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/mctp/mctp-serial.c +1
-2@@ -536,13 +536,12 @@ struct test_chunk_tx {static void test_next_chunk_len (struct kunit *test) { -struct mctp_serial devx; +struct mctp_serial devx = { };struct mctp_serial *dev = &devx;int next;const struct test_chunk_tx *params = test->param_value; -memset (dev,0x0 ,sizeof (*dev));memcpy (dev->txbuf, params->input, params->input_len); dev->txlen = params->input_len;
Hi David,
Just a quick follow-up on this thread. When you have a moment, I would love to hear your thoughts on my previous email.
Please let me know how you would like me to proceed with this patch.
Thanks & Regards ,
Manish
Quoted 71 lines · Manish Baing
Hi David,
I understand that this might just be unnecessary churn for the networking subsystem, and I am perfectly fine dropping the patch if that is the case.
However, for my own learning, I would love to get your perspective on this. I was carrying over a pattern from recent cleanups in the IIO subsystem [1],
as empty brace initialization was noted as the preferred approach in those discussions (including by Kees Cook [2]).Is the reasoning behind that recommendation just not applicable to netdev,or is the policy here strictly against code churn unless it fixes a tangible bug?
Thanks for the guidance.
[1]: https://lore.kernel.org/all/20250611-iio-zero-init-stack-with-instead-of-memset-v1-0-ebb2d0a24302@baylibre.com/
[2]: https://lore.kernel.org/linux-iio/202505090942.48EBF01B@keescook/Regards,
ManishQuoted 43 lines · David Laight
Quoted 4 lines · On Sat, 30 May 2026 22:46:46 +0000 Manish Baing <[email protected]>…
Use empty brace initialization (= {}) instead of explicit
memset()to zero-initialize stack memory to simplify the code.No functional change.
Isn't it also entirely pointless?
-- David
Quoted 29 lines
Signed-off-by Manish Baing <[email protected]>---
Changes in v2:
- Fixed a compilation error caused by a duplicate variable declaration caught by the kernel test robot.drivers/net/mctp/mctp-serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/mctp/mctp-serial.c +1
-2@@ -536,13 +536,12 @@ struct test_chunk_tx {static void test_next_chunk_len (struct kunit *test) { -struct mctp_serial devx; +struct mctp_serial devx = { };struct mctp_serial *dev = &devx;int next;const struct test_chunk_tx *params = test->param_value; -memset (dev,0x0 ,sizeof (*dev));memcpy (dev->txbuf, params->input, params->input_len); dev->txlen = params->input_len;
Hi David,
Just a quick follow-up on this thread.
Please let me know how you would like me to proceed with this patch.
Thanks & Regards ,
Manish
Quoted 82 lines · Manish Baing
Hi David,
Just a quick follow-up on this thread. When you have a moment, I would love to hear your thoughts on my previous email.
Please let me know how you would like me to proceed with this patch.Thanks & Regards ,
ManishQuoted 71 lines · Manish Baing
Hi David,
I understand that this might just be unnecessary churn for the networking subsystem, and I am perfectly fine dropping the patch if that is the case.
However, for my own learning, I would love to get your perspective on this. I was carrying over a pattern from recent cleanups in the IIO subsystem [1],
as empty brace initialization was noted as the preferred approach in those discussions (including by Kees Cook [2]).Is the reasoning behind that recommendation just not applicable to netdev,or is the policy here strictly against code churn unless it fixes a tangible bug?
Thanks for the guidance.
[1]: https://lore.kernel.org/all/20250611-iio-zero-init-stack-with-instead-of-memset-v1-0-ebb2d0a24302@baylibre.com/
[2]: https://lore.kernel.org/linux-iio/202505090942.48EBF01B@keescook/Regards,
ManishQuoted 43 lines · David Laight
Quoted 4 lines · On Sat, 30 May 2026 22:46:46 +0000 Manish Baing <[email protected]>…
Use empty brace initialization (= {}) instead of explicit
memset()to zero-initialize stack memory to simplify the code.No functional change.
Isn't it also entirely pointless?
-- David
Quoted 29 lines
Signed-off-by Manish Baing <[email protected]>---
Changes in v2:
- Fixed a compilation error caused by a duplicate variable declaration caught by the kernel test robot.drivers/net/mctp/mctp-serial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/mctp/mctp-serial.c +1
-2@@ -536,13 +536,12 @@ struct test_chunk_tx {static void test_next_chunk_len (struct kunit *test) { -struct mctp_serial devx; +struct mctp_serial devx = { };struct mctp_serial *dev = &devx;int next;const struct test_chunk_tx *params = test->param_value; -memset (dev,0x0 ,sizeof (*dev));memcpy (dev->txbuf, params->input, params->input_len); dev->txlen = params->input_len;