summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/w1/slaves/w1_ds2433.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c
index 0c67082c8bb7..87df76094e03 100644
--- a/drivers/w1/slaves/w1_ds2433.c
+++ b/drivers/w1/slaves/w1_ds2433.c
@@ -28,6 +28,7 @@
#define W1_PAGE_SIZE 32
#define W1_PAGE_BITS 5
#define W1_PAGE_MASK 0x1F
+#define W1_VALIDCRC_MAX 32
#define W1_F23_READ_EEPROM 0xF0
#define W1_F23_WRITE_SCRATCH 0x0F
@@ -48,8 +49,8 @@ static const struct ds2433_config config_f23 = {
struct w1_f23_data {
#ifdef CONFIG_W1_SLAVE_DS2433_CRC
- u8 *memory;
- u32 validcrc;
+ u8 *memory;
+ DECLARE_BITMAP(validcrc, W1_VALIDCRC_MAX);
#endif
const struct ds2433_config *cfg;
};
@@ -76,11 +77,11 @@ static int w1_f23_refresh_block(struct w1_slave *sl, struct w1_f23_data *data,
u8 wrbuf[3];
int off = block * W1_PAGE_SIZE;
- if (data->validcrc & (1 << block))
+ if (test_bit(block, data->validcrc))
return 0;
if (w1_reset_select_slave(sl)) {
- data->validcrc = 0;
+ bitmap_zero(data->validcrc, data->cfg->page_count);
return -EIO;
}
@@ -92,7 +93,7 @@ static int w1_f23_refresh_block(struct w1_slave *sl, struct w1_f23_data *data,
/* cache the block if the CRC is valid */
if (crc16(CRC16_INIT, &data->memory[off], W1_PAGE_SIZE) == CRC16_VALID)
- data->validcrc |= (1 << block);
+ set_bit(block, data->validcrc);
return 0;
}
@@ -207,7 +208,7 @@ static int w1_f23_write(struct w1_slave *sl, int addr, int len, const u8 *data)
/* Reset the bus to wake up the EEPROM (this may not be needed) */
w1_reset_bus(sl->master);
#ifdef CONFIG_W1_SLAVE_DS2433_CRC
- f23->validcrc &= ~(1 << (addr >> W1_PAGE_BITS));
+ clear_bit(addr >> W1_PAGE_BITS, f23->validcrc);
#endif
return 0;
}
@@ -290,11 +291,17 @@ static int w1_f23_add_slave(struct w1_slave *sl)
data->cfg = &config_f23;
#ifdef CONFIG_W1_SLAVE_DS2433_CRC
+ if (data->cfg->page_count > W1_VALIDCRC_MAX) {
+ dev_err(&sl->dev, "page count too big for crc bitmap\n");
+ kfree(data);
+ return -EINVAL;
+ }
data->memory = kzalloc(data->cfg->eeprom_size, GFP_KERNEL);
if (!data->memory) {
kfree(data);
return -ENOMEM;
}
+ bitmap_zero(data->validcrc, data->cfg->page_count);
#endif /* CONFIG_W1_SLAVE_DS2433_CRC */
sl->family_data = data;