* [PATCH 0/7] hwmon: zero-initialization instead of memset
@ 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
` (6 more replies)
0 siblings, 7 replies; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
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/
Manish Baing (7):
hwmon: drivetemp: Use zero-initialization instead of memset()
hwmon: f71882fg: Use zero-initialization instead of memset()
hwmon: ltc2947-core: Use zero-initialization instead of memset()
hwmon: nct6683: Use zero-initialization instead of memset()
hwmon: nct6775-platform: Use zero-initialization instead of memset()
hwmon: pmbus: adm1266: Use zero-initialization instead of memset()
hwmon: it87: Use zero-initialization instead of memset()
drivers/hwmon/drivetemp.c | 3 +--
drivers/hwmon/f71882fg.c | 4 +---
drivers/hwmon/it87.c | 3 +--
drivers/hwmon/ltc2947-core.c | 4 +---
drivers/hwmon/nct6683.c | 4 ++--
drivers/hwmon/nct6775-platform.c | 4 ++--
drivers/hwmon/pmbus/adm1266.c | 4 +---
7 files changed, 9 insertions(+), 17 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/7] hwmon: drivetemp: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset Manish Baing
@ 2026-05-30 22:13 ` Manish Baing
2026-05-30 22:17 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 2/7] hwmon: f71882fg: " Manish Baing
` (5 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
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>
---
drivers/hwmon/drivetemp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c
index 002e0660a0b8..b75cd5f5246e 100644
--- a/drivers/hwmon/drivetemp.c
+++ b/drivers/hwmon/drivetemp.c
@@ -161,11 +161,10 @@ static int drivetemp_scsi_command(struct drivetemp_data *st,
u8 ata_command, u8 feature,
u8 lba_low, u8 lba_mid, u8 lba_high)
{
- u8 scsi_cmd[MAX_COMMAND_SIZE];
+ u8 scsi_cmd[MAX_COMMAND_SIZE] = { };
enum req_op op;
int err;
- memset(scsi_cmd, 0, sizeof(scsi_cmd));
scsi_cmd[0] = ATA_16;
if (ata_command == ATA_CMD_SMART && feature == SMART_WRITE_LOG) {
scsi_cmd[1] = (5 << 1); /* PIO Data-out */
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 2/7] hwmon: f71882fg: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset 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 ` Manish Baing
2026-05-30 22:18 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 3/7] hwmon: ltc2947-core: " Manish Baing
` (4 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
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>
---
drivers/hwmon/f71882fg.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 204059d2de6c..c1d02d4e7b76 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -2667,9 +2667,7 @@ static int __init f71882fg_init(void)
{
int err;
int address;
- struct f71882fg_sio_data sio_data;
-
- memset(&sio_data, 0, sizeof(sio_data));
+ struct f71882fg_sio_data sio_data = { };
address = f71882fg_find(0x2e, &sio_data);
if (address < 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 3/7] hwmon: ltc2947-core: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset 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 ` Manish Baing
2026-05-30 22:32 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 4/7] hwmon: nct6683: " Manish Baing
` (3 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
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>
---
drivers/hwmon/ltc2947-core.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/hwmon/ltc2947-core.c b/drivers/hwmon/ltc2947-core.c
index ad7120d1e469..d95265986b18 100644
--- a/drivers/hwmon/ltc2947-core.c
+++ b/drivers/hwmon/ltc2947-core.c
@@ -273,11 +273,9 @@ static int ltc2947_alarm_read(struct ltc2947_data *st, const u8 reg,
{
u8 offset = reg - LTC2947_REG_STATUS;
/* +1 to include status reg */
- char alarms[LTC2947_ALERTS_SIZE + 1];
+ char alarms[LTC2947_ALERTS_SIZE + 1] = { };
int ret = 0;
- memset(alarms, 0, sizeof(alarms));
-
ret = regmap_write(st->map, LTC2947_REG_PAGE_CTRL, LTC2947_PAGE0);
if (ret)
return ret;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 4/7] hwmon: nct6683: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset Manish Baing
` (2 preceding siblings ...)
2026-05-30 22:13 ` [PATCH 3/7] hwmon: ltc2947-core: " Manish Baing
@ 2026-05-30 22:13 ` Manish Baing
2026-05-30 22:35 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 5/7] hwmon: nct6775-platform: " Manish Baing
` (2 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
Reduce the scope of 'struct resource res' by moving it inside the for-loop
and using empty brace initialization (= {}). This ensures the structure is
safely zero-initialized on every iteration, allowing for the safe removal
of explicit memset() call.
No functional change.
Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
---
drivers/hwmon/nct6683.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
index 0581770380cc..bd30867f9e7c 100644
--- a/drivers/hwmon/nct6683.c
+++ b/drivers/hwmon/nct6683.c
@@ -1437,7 +1437,6 @@ static int __init sensors_nct6683_init(void)
{
struct nct6683_sio_data sio_data;
int sioaddr[2] = { 0x2e, 0x4e };
- struct resource res;
bool found = false;
int address;
int i, err;
@@ -1454,6 +1453,8 @@ static int __init sensors_nct6683_init(void)
* nct6683 hardware monitor, and call probe()
*/
for (i = 0; i < ARRAY_SIZE(pdev); i++) {
+ struct resource res = { };
+
address = nct6683_find(sioaddr[i], &sio_data);
if (address <= 0)
continue;
@@ -1471,7 +1472,6 @@ static int __init sensors_nct6683_init(void)
if (err)
goto exit_device_put;
- memset(&res, 0, sizeof(res));
res.name = DRVNAME;
res.start = address + IOREGION_OFFSET;
res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 5/7] hwmon: nct6775-platform: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset Manish Baing
` (3 preceding siblings ...)
2026-05-30 22:13 ` [PATCH 4/7] hwmon: nct6683: " Manish Baing
@ 2026-05-30 22:13 ` Manish Baing
2026-05-30 22:37 ` sashiko-bot
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
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
Reduce the scope of 'struct resource res' by moving it inside the for-loop
and using empty brace initialization (= {}). This ensures the structure is
safely zero-initialized on every iteration, allowing for the safe removal
of explicit memset() call.
No functional change.
Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
---
drivers/hwmon/nct6775-platform.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/nct6775-platform.c b/drivers/hwmon/nct6775-platform.c
index 1975399ac440..b73086a56d97 100644
--- a/drivers/hwmon/nct6775-platform.c
+++ b/drivers/hwmon/nct6775-platform.c
@@ -1528,7 +1528,6 @@ static int __init sensors_nct6775_platform_init(void)
int i, err;
bool found = false;
int address;
- struct resource res;
struct nct6775_sio_data sio_data;
int sioaddr[2] = { 0x2e, 0x4e };
enum sensor_access access = access_direct;
@@ -1562,6 +1561,8 @@ static int __init sensors_nct6775_platform_init(void)
* nct6775 hardware monitor, and call probe()
*/
for (i = 0; i < ARRAY_SIZE(pdev); i++) {
+ struct resource res = { };
+
sio_data.sio_outb = superio_outb;
sio_data.sio_inb = superio_inb;
sio_data.sio_select = superio_select;
@@ -1596,7 +1597,6 @@ static int __init sensors_nct6775_platform_init(void)
goto exit_device_put;
if (sio_data.access == access_direct) {
- memset(&res, 0, sizeof(res));
res.name = DRVNAME;
res.start = address + IOREGION_OFFSET;
res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6/7] hwmon: pmbus: adm1266: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset Manish Baing
` (4 preceding siblings ...)
2026-05-30 22:13 ` [PATCH 5/7] hwmon: nct6775-platform: " Manish Baing
@ 2026-05-30 22:13 ` Manish Baing
2026-05-30 22:40 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 7/7] hwmon: it87: " Manish Baing
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
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>
---
drivers/hwmon/pmbus/adm1266.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index 6f6ad7b20e9a..806b92473a4f 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -449,13 +449,11 @@ static int adm1266_config_nvmem(struct adm1266_data *data)
static int adm1266_set_rtc(struct adm1266_data *data)
{
time64_t kt;
- char write_buf[6];
+ char write_buf[6] = { };
int i;
kt = ktime_get_real_seconds();
- memset(write_buf, 0, sizeof(write_buf));
-
for (i = 0; i < 4; i++)
write_buf[2 + i] = (kt >> (i * 8)) & 0xFF;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 7/7] hwmon: it87: Use zero-initialization instead of memset()
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset Manish Baing
` (5 preceding siblings ...)
2026-05-30 22:13 ` [PATCH 6/7] hwmon: pmbus: adm1266: " Manish Baing
@ 2026-05-30 22:13 ` Manish Baing
2026-05-30 22:47 ` sashiko-bot
6 siblings, 1 reply; 15+ messages in thread
From: Manish Baing @ 2026-05-30 22:13 UTC (permalink / raw)
To: linux, jdelvare, nuno.sa
Cc: abdurrahman, bartosz.golaszewski, linusw, linux-hwmon,
linux-kernel, skhan, me, manishbaing2789
Reduce the scope of 'struct it87_sio_data sio_data' by moving it inside
the for-loop and using empty brace initialization (= {}). This ensures
the structure is safely zero-initialized on every iteration, allowing for
the safe removal of the explicit memset() call.
No functional change.
Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
---
drivers/hwmon/it87.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 5fd310662ee4..f3f8d835ff92 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -3777,7 +3777,6 @@ MODULE_DEVICE_TABLE(dmi, it87_dmi_table);
static int __init sm_it87_init(void)
{
int sioaddr[2] = { REG_2E, REG_4E };
- struct it87_sio_data sio_data;
unsigned short isa_address[2];
bool found = false;
int i, err;
@@ -3789,7 +3788,7 @@ static int __init sm_it87_init(void)
dmi_check_system(it87_dmi_table);
for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
- memset(&sio_data, 0, sizeof(struct it87_sio_data));
+ struct it87_sio_data sio_data = { };
isa_address[i] = 0;
err = it87_find(sioaddr[i], &isa_address[i], &sio_data, i);
if (err || isa_address[i] == 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 1/7] hwmon: drivetemp: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 1/7] hwmon: drivetemp: Use zero-initialization instead of memset() Manish Baing
@ 2026-05-30 22:17 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:17 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
> 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>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=1
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/7] hwmon: f71882fg: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 2/7] hwmon: f71882fg: " Manish Baing
@ 2026-05-30 22:18 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:18 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
> 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>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=2
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/7] hwmon: ltc2947-core: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 3/7] hwmon: ltc2947-core: " Manish Baing
@ 2026-05-30 22:32 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:32 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
> 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>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=3
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/7] hwmon: nct6683: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 4/7] hwmon: nct6683: " Manish Baing
@ 2026-05-30 22:35 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:35 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
> Reduce the scope of 'struct resource res' by moving it inside the for-loop
> and using empty brace initialization (= {}). This ensures the structure is
> safely zero-initialized on every iteration, allowing for the safe removal
> of explicit memset() call.
>
> No functional change.
>
> Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=4
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 5/7] hwmon: nct6775-platform: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 5/7] hwmon: nct6775-platform: " Manish Baing
@ 2026-05-30 22:37 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:37 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
> Reduce the scope of 'struct resource res' by moving it inside the for-loop
> and using empty brace initialization (= {}). This ensures the structure is
> safely zero-initialized on every iteration, allowing for the safe removal
> of explicit memset() call.
>
> No functional change.
>
> Signed-off-by: Manish Baing <manishbaing2789@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=5
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 6/7] hwmon: pmbus: adm1266: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 6/7] hwmon: pmbus: adm1266: " Manish Baing
@ 2026-05-30 22:40 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:40 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
> 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>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=6
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 7/7] hwmon: it87: Use zero-initialization instead of memset()
2026-05-30 22:13 ` [PATCH 7/7] hwmon: it87: " Manish Baing
@ 2026-05-30 22:47 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-05-30 22:47 UTC (permalink / raw)
To: Manish Baing; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Replacing memset() with empty brace initialization leaves struct padding bytes uninitialized, causing a KMSAN uninit-value warning when copied via platform_device_add_data().
--
commit 429f8b305f54cb034b99374e3bdaa61a1ba8f424
Author: Manish Baing <manishbaing2789@gmail.com>
hwmon: it87: Use zero-initialization instead of memset()
This commit reduces the scope of 'sio_data' by moving it inside the for-loop
and replacing the explicit memset() with empty brace initialization.
> diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
> index 5fd310662ee43..f3f8d835ff92a 100644
> --- a/drivers/hwmon/it87.c
> +++ b/drivers/hwmon/it87.c
> @@ -3777,7 +3777,6 @@ MODULE_DEVICE_TABLE(dmi, it87_dmi_table);
> static int __init sm_it87_init(void)
> {
> int sioaddr[2] = { REG_2E, REG_4E };
> - struct it87_sio_data sio_data;
> unsigned short isa_address[2];
> bool found = false;
> int i, err;
> @@ -3789,7 +3788,7 @@ static int __init sm_it87_init(void)
> dmi_check_system(it87_dmi_table);
>
> for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
> - memset(&sio_data, 0, sizeof(struct it87_sio_data));
> + struct it87_sio_data sio_data = { };
[Severity: Medium]
Does replacing memset() with empty brace initialization leave struct padding
bytes uninitialized?
Empty brace initialization is often lowered by compilers to member-wise
zeroing, which skips padding bytes.
When this structure is passed to it87_device_add(), it is copied
byte-by-byte via platform_device_add_data():
drivers/hwmon/it87.c:it87_device_add() {
...
err = platform_device_add_data(pdev, sio_data,
sizeof(struct it87_sio_data));
...
}
Because platform_device_add_data() uses kmemdup() to copy the entire size of
the structure, won't reading the uninitialized padding bytes trigger a KMSAN
uninitialized-value warning during driver probe?
> isa_address[i] = 0;
> err = it87_find(sioaddr[i], &isa_address[i], &sio_data, i);
> if (err || isa_address[i] == 0)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530221353.159461-1-manishbaing2789@gmail.com?part=7
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-05-30 22:47 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-30 22:13 [PATCH 0/7] hwmon: zero-initialization instead of memset Manish Baing
2026-05-30 22:13 ` [PATCH 1/7] hwmon: drivetemp: Use zero-initialization instead of memset() Manish Baing
2026-05-30 22:17 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 2/7] hwmon: f71882fg: " Manish Baing
2026-05-30 22:18 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 3/7] hwmon: ltc2947-core: " Manish Baing
2026-05-30 22:32 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 4/7] hwmon: nct6683: " Manish Baing
2026-05-30 22:35 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 5/7] hwmon: nct6775-platform: " Manish Baing
2026-05-30 22:37 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 6/7] hwmon: pmbus: adm1266: " Manish Baing
2026-05-30 22:40 ` sashiko-bot
2026-05-30 22:13 ` [PATCH 7/7] hwmon: it87: " Manish Baing
2026-05-30 22:47 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox