Skip to contentSkip to conversation

mctp: serial: replace memset with zero-initialization

PATCH In review Manish Baing 2 participants 5 messages May 30 – Jun 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index 26c9a33fd636..df721ca4e07b 100644
@@ -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
#1 lore raw
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

---
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
index 26c9a33fd636..df721ca4e07b 100644
@@ -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;
 
#2 lore raw

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

---
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
index 26c9a33fd636..df721ca4e07b 100644
@@ -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;
 
#3 lore raw

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,
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

---
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
index 26c9a33fd636..df721ca4e07b 100644
@@ -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;
 
#4 lore raw

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 ,
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,
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

---
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
index 26c9a33fd636..df721ca4e07b 100644
@@ -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;