mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Manish Baing <manishbaing2789@gmail.com>
Cc: jdelvare@suse.com, nuno.sa@analog.com, abdurrahman@nexthop.ai,
	bartosz.golaszewski@oss.qualcomm.com, linusw@kernel.org,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	skhan@linuxfoundation.org, me@brighamcampbell.com
Subject: Re: [PATCH 0/7] hwmon: zero-initialization instead of memset
Date: Thu, 25 Jun 2026 18:59:31 -0700	[thread overview]
Message-ID: <5cf25e6a-1d58-41c4-a628-3ff125ca5f42@roeck-us.net> (raw)
In-Reply-To: <CAJvdc_fpMR1T-p0YWOcmFEZ+YB+LHAQtxRSgMCaDti3E0cLqGg@mail.gmail.com>

On 6/25/26 09:04, Manish Baing wrote:
> Hi Guenter,
> 
> Thank you for catching the struct padding risk. You are completely
> right—Patch 7 (it87.c) would trigger a KMSAN uninit-value warning due
> to the kmemdup() copy in platform_device_add_data(). I will drop that
> patch entirely.
> 
> I have audited the other six drivers in this series and verified that
> their variables are never passed to memcmp(), kmemdup(), or hashed, so
> the = {} initialization is perfectly safe there.
> 
> While this does not fix an active bug, the goal is to follow a cleanup
> pattern  recently discussed for the IIO subsystem [1],[2]
> 1.Better performance: It removes the need for an extra function call.
> Instead, the compiler clears the memory directly and more efficiently.
> 2.Safer code: It prevents accidental memory leaks that happen when
> developers make a typo in the sizeof() calculation.
> 
> Would you be open to a v2 that includes just the six safe patches to
> modernize these initializations?
> 

Not really. I would not mind if there was a safe means to initialize
a data structure without risking holes and without memset(). In the
absence of that I rather play safe than sorry (and apparently we have
a different opinion about the definition of "safe").

Guenter

> [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/
> 
> Thanks for your time and guidance,
> 
> Thanks & Regards,
> Manish
> 
> On Sun, Jun 7, 2026 at 9:42 PM Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> On 5/30/26 15:13, Manish Baing wrote:
>>> Hi all,
>>>
>>> This patch series cleans up memory initialization across several
>>> hardware monitoring (hwmon) drivers by replacing explicit memset() calls
>>> with empty brace initialization (= {}).
>>>
>>> Following similar cleanups in the IIO subsystem [1], this series updates
>>> these drivers to stop using memset() for stack memory initialization.
>>> As noted in those discussions [2], using empty brace initialization (= {})
>>> is the preferred approach.
>>>
>>> Beyond simple replacements, a few drivers (nct6683, nct6775-platform, it87)
>>> were using memset() inside a for-loop. To fix this, the variable
>>> declarationwas moved directly inside the loop and zero-initialized there.
>>> This safely resets the data on every iteration and makes the code much
>>> cleaner.
>>>
>>> Testing:
>>> - Compiled all modified files using `make W=1` with no warnings or errors.
>>>
>>> [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/
>>
>> That discussion does not fully address a problem I had seen previously,
>> where {} did _not_ zero-fill all holes, causing subsequent memcmp()
>> failures on affected data structures. It took a lot a lot of debugging
>> to find and fix that problem. Given that, I am not inclined to accept
>> this series unless someone convinces me that it fixes an actual problem
>> _and_ that each and every instance of the changes is not used in a
>> subsequent memcmp().
>>
>> Guenter
>>
> 


  reply	other threads:[~2026-06-26  1:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-30 22:13 Manish Baing
2026-05-30 22:13 ` [PATCH 1/7] hwmon: drivetemp: Use zero-initialization instead of memset() Manish Baing
2026-05-30 22:13 ` [PATCH 2/7] hwmon: f71882fg: " Manish Baing
2026-05-30 22:13 ` [PATCH 3/7] hwmon: ltc2947-core: " Manish Baing
2026-05-30 22:13 ` [PATCH 4/7] hwmon: nct6683: " Manish Baing
2026-05-30 22:13 ` [PATCH 5/7] hwmon: nct6775-platform: " Manish Baing
2026-05-30 22:13 ` [PATCH 6/7] hwmon: pmbus: adm1266: " Manish Baing
2026-05-30 22:13 ` [PATCH 7/7] hwmon: it87: " Manish Baing
2026-06-06 19:22   ` Manish Baing
2026-06-07 16:12 ` [PATCH 0/7] hwmon: zero-initialization instead of memset Guenter Roeck
2026-06-25 16:04   ` Manish Baing
2026-06-26  1:59     ` Guenter Roeck [this message]
2026-06-26  4:43       ` Manish Baing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5cf25e6a-1d58-41c4-a628-3ff125ca5f42@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=abdurrahman@nexthop.ai \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=jdelvare@suse.com \
    --cc=linusw@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manishbaing2789@gmail.com \
    --cc=me@brighamcampbell.com \
    --cc=nuno.sa@analog.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®