Skip to content

Commit 0769ebe

Browse files
committed
w1: ds2406: use crc16() instead of crc16_byte() loop
Instead of looping through each byte and calling crc16_byte(), instead just call crc16() on the whole buffer. No functional change. Acked-by: Krzysztof Kozlowski <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent e8d72b7 commit 0769ebe

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

drivers/w1/slaves/w1_ds2406.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ static ssize_t w1_f12_read_state(
2929
{
3030
u8 w1_buf[6] = {W1_F12_FUNC_READ_STATUS, 7, 0, 0, 0, 0};
3131
struct w1_slave *sl = kobj_to_w1_slave(kobj);
32-
u16 crc = 0;
33-
int i;
3432
ssize_t rtnval = 1;
3533

3634
if (off != 0)
@@ -47,9 +45,7 @@ static ssize_t w1_f12_read_state(
4745

4846
w1_write_block(sl->master, w1_buf, 3);
4947
w1_read_block(sl->master, w1_buf+3, 3);
50-
for (i = 0; i < 6; i++)
51-
crc = crc16_byte(crc, w1_buf[i]);
52-
if (crc == 0xb001) /* good read? */
48+
if (crc16(0, w1_buf, sizeof(w1_buf)) == 0xb001) /* good read? */
5349
*buf = ((w1_buf[3]>>5)&3)|0x30;
5450
else
5551
rtnval = -EIO;
@@ -66,8 +62,6 @@ static ssize_t w1_f12_write_output(
6662
{
6763
struct w1_slave *sl = kobj_to_w1_slave(kobj);
6864
u8 w1_buf[6] = {W1_F12_FUNC_WRITE_STATUS, 7, 0, 0, 0, 0};
69-
u16 crc = 0;
70-
int i;
7165
ssize_t rtnval = 1;
7266

7367
if (count != 1 || off != 0)
@@ -83,9 +77,7 @@ static ssize_t w1_f12_write_output(
8377
w1_buf[3] = (((*buf)&3)<<5)|0x1F;
8478
w1_write_block(sl->master, w1_buf, 4);
8579
w1_read_block(sl->master, w1_buf+4, 2);
86-
for (i = 0; i < 6; i++)
87-
crc = crc16_byte(crc, w1_buf[i]);
88-
if (crc == 0xb001) /* good read? */
80+
if (crc16(0, w1_buf, sizeof(w1_buf)) == 0xb001) /* good read? */
8981
w1_write_8(sl->master, 0xFF);
9082
else
9183
rtnval = -EIO;

0 commit comments

Comments
 (0)