Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] hwmon: pwm-fan: Add const to channels allocation type
@ 2026-09-17 21:14 Kees Cook
  2026-09-18 15:05 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2026-09-17 21:14 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Kees Cook, Kees Cook, linux-hwmon, linux-kernel, linux-hardening

From: Kees Cook <kees+treewide@kernel.org>

In preparation for making the devm_kmalloc family of allocators type
aware, we need to make sure that the returned type from the allocation
matches the type of the variable being assigned. (Before, the allocator
would always return "void *", which can be implicitly cast to any
pointer type.)

The assigned type is "const struct hwmon_channel_info **", but the
converted allocation type would be "struct hwmon_channel_info **", which
is the same type without the const qualifier. As there is no general way
to safely add const qualifiers, take the size from the assignment target
instead. No change in allocation size results.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
drivers/hwmon/pwm-fan.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
---
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: <linux-hwmon@vger.kernel.org>
---
 drivers/hwmon/pwm-fan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 3b87f65bae05..db19a054f4f4 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -613,7 +613,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
 	}
 
 	channels = devm_kcalloc(dev, channel_count + 1,
-				sizeof(struct hwmon_channel_info *), GFP_KERNEL);
+				sizeof(*channels), GFP_KERNEL);
 	if (!channels)
 		return -ENOMEM;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-18 15:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 21:14 [PATCH] hwmon: pwm-fan: Add const to channels allocation type Kees Cook
2026-09-18 15:05 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox