[PATCH v2] mctp: serial: replace memset with zero-initialization

Manish Baing posted 1 patch 1 week, 1 day ago
drivers/net/mctp/mctp-serial.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH v2] mctp: serial: replace memset with zero-initialization
Posted by Manish Baing 1 week, 1 day ago
Use empty brace initialization (= {}) instead of explicit memset()
to zero-initialize stack memory to simplify the code.

No functional change.

Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
---
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(-)

diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
index 26c9a33fd636..df721ca4e07b 100644
--- a/drivers/net/mctp/mctp-serial.c
+++ b/drivers/net/mctp/mctp-serial.c
@@ -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.43.0
Re: [PATCH v2] mctp: serial: replace memset with zero-initialization
Posted by David Laight 1 week ago
On Sat, 30 May 2026 22:46:46 +0000
Manish Baing <manishbaing2789@gmail.com> wrote:

> 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

> 
> Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
> ---
> 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(-)
> 
> diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
> index 26c9a33fd636..df721ca4e07b 100644
> --- a/drivers/net/mctp/mctp-serial.c
> +++ b/drivers/net/mctp/mctp-serial.c
> @@ -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;
>
Re: [PATCH v2] mctp: serial: replace memset with zero-initialization
Posted by Manish Baing 1 week ago
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


On Sun, May 31, 2026 at 2:42 PM David Laight
<david.laight.linux@gmail.com> wrote:
>
> On Sat, 30 May 2026 22:46:46 +0000
> Manish Baing <manishbaing2789@gmail.com> wrote:
>
> > 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
>
> >
> > Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
> > ---
> > 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(-)
> >
> > diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
> > index 26c9a33fd636..df721ca4e07b 100644
> > --- a/drivers/net/mctp/mctp-serial.c
> > +++ b/drivers/net/mctp/mctp-serial.c
> > @@ -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;
> >
>
Re: [PATCH v2] mctp: serial: replace memset with zero-initialization
Posted by Manish Baing 1 day, 11 hours ago
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

On Sun, May 31, 2026 at 3:06 PM Manish Baing <manishbaing2789@gmail.com> wrote:
>
> 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
>
>
> On Sun, May 31, 2026 at 2:42 PM David Laight
> <david.laight.linux@gmail.com> wrote:
> >
> > On Sat, 30 May 2026 22:46:46 +0000
> > Manish Baing <manishbaing2789@gmail.com> wrote:
> >
> > > 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
> >
> > >
> > > Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
> > > ---
> > > 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(-)
> > >
> > > diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
> > > index 26c9a33fd636..df721ca4e07b 100644
> > > --- a/drivers/net/mctp/mctp-serial.c
> > > +++ b/drivers/net/mctp/mctp-serial.c
> > > @@ -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;
> > >
> >