[PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference
From: Lee Jones
Date: Wed Dec 02 2026 - 04:38:42 EST
w1_f1C_add_slave() only allocates sl->family_data when
w1_enable_crccheck is enabled at attach time. Because
w1_enable_crccheck can be toggled at runtime through the crccheck sysfs
attribute, enabling it after a slave has attached causes subsequent
EEPROM reads and writes to dereference a NULL sl->family_data pointer.
Conversely, writing while crccheck is disabled skips invalidating
f1C->validcrc, leaving stale cached pages if crccheck is later
re-enabled.
Unconditionally allocate sl->family_data in w1_f1C_add_slave() and
always invalidate the page CRC cache entry in w1_f1C_write().
Fixes: fbf7f7b4e2ae ("w1: Add 1-wire slave device driver for DS28E04-100")
Closes: https://sashiko.dev/#/bug/linux-2eaa9a0e-9abb-4060-9da4-7d85a0bb8f0a
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/w1/slaves/w1_ds28e04.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/w1/slaves/w1_ds28e04.c b/drivers/w1/slaves/w1_ds28e04.c
index 30fb8415b659..dca64d608ea8 100644
--- a/drivers/w1/slaves/w1_ds28e04.c
+++ b/drivers/w1/slaves/w1_ds28e04.c
@@ -211,10 +211,8 @@ static int w1_f1C_write(struct w1_slave *sl, int addr, int len, const u8 *data)
if (!w1_strong_pullup)
msleep(tm);
- if (w1_enable_crccheck) {
- /* invalidate cached data */
- f1C->validcrc &= ~(1 << (addr >> W1_PAGE_BITS));
- }
+ /* invalidate cached data */
+ f1C->validcrc &= ~(1 << (addr >> W1_PAGE_BITS));
/* Reset the bus to wake up the EEPROM (this may not be needed) */
w1_reset_bus(sl->master);
@@ -381,14 +379,12 @@ static const struct attribute_group *w1_f1C_groups[] = {
static int w1_f1C_add_slave(struct w1_slave *sl)
{
- struct w1_f1C_data *data = NULL;
+ struct w1_f1C_data *data;
- if (w1_enable_crccheck) {
- data = kzalloc_obj(struct w1_f1C_data);
- if (!data)
- return -ENOMEM;
- sl->family_data = data;
- }
+ data = kzalloc_obj(struct w1_f1C_data);
+ if (!data)
+ return -ENOMEM;
+ sl->family_data = data;
return 0;
}
--
2.56.1.911.g883d8bcb20-goog