All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>
Subject: [PATCH 1/2] w1: ds2406: use crc16() instead of crc16_byte() loop
Date: Mon, 12 May 2025 19:21:14 -0700	[thread overview]
Message-ID: <20250513022115.39109-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20250513022115.39109-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

Instead of looping through each byte and calling crc16_byte(), instead
just call crc16() on the whole buffer.  No functional change.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/w1/slaves/w1_ds2406.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/w1/slaves/w1_ds2406.c b/drivers/w1/slaves/w1_ds2406.c
index 1cae9b243ff8..76026d615111 100644
--- a/drivers/w1/slaves/w1_ds2406.c
+++ b/drivers/w1/slaves/w1_ds2406.c
@@ -27,12 +27,10 @@ static ssize_t w1_f12_read_state(
 	const struct bin_attribute *bin_attr,
 	char *buf, loff_t off, size_t count)
 {
 	u8 w1_buf[6] = {W1_F12_FUNC_READ_STATUS, 7, 0, 0, 0, 0};
 	struct w1_slave *sl = kobj_to_w1_slave(kobj);
-	u16 crc = 0;
-	int i;
 	ssize_t rtnval = 1;
 
 	if (off != 0)
 		return 0;
 	if (!buf)
@@ -45,13 +43,11 @@ static ssize_t w1_f12_read_state(
 		return -EIO;
 	}
 
 	w1_write_block(sl->master, w1_buf, 3);
 	w1_read_block(sl->master, w1_buf+3, 3);
-	for (i = 0; i < 6; i++)
-		crc = crc16_byte(crc, w1_buf[i]);
-	if (crc == 0xb001) /* good read? */
+	if (crc16(0, w1_buf, sizeof(w1_buf)) == 0xb001) /* good read? */
 		*buf = ((w1_buf[3]>>5)&3)|0x30;
 	else
 		rtnval = -EIO;
 
 	mutex_unlock(&sl->master->bus_mutex);
@@ -64,12 +60,10 @@ static ssize_t w1_f12_write_output(
 	const struct bin_attribute *bin_attr,
 	char *buf, loff_t off, size_t count)
 {
 	struct w1_slave *sl = kobj_to_w1_slave(kobj);
 	u8 w1_buf[6] = {W1_F12_FUNC_WRITE_STATUS, 7, 0, 0, 0, 0};
-	u16 crc = 0;
-	int i;
 	ssize_t rtnval = 1;
 
 	if (count != 1 || off != 0)
 		return -EFAULT;
 
@@ -81,13 +75,11 @@ static ssize_t w1_f12_write_output(
 	}
 
 	w1_buf[3] = (((*buf)&3)<<5)|0x1F;
 	w1_write_block(sl->master, w1_buf, 4);
 	w1_read_block(sl->master, w1_buf+4, 2);
-	for (i = 0; i < 6; i++)
-		crc = crc16_byte(crc, w1_buf[i]);
-	if (crc == 0xb001) /* good read? */
+	if (crc16(0, w1_buf, sizeof(w1_buf)) == 0xb001) /* good read? */
 		w1_write_8(sl->master, 0xFF);
 	else
 		rtnval = -EIO;
 
 	mutex_unlock(&sl->master->bus_mutex);
-- 
2.49.0


  reply	other threads:[~2025-05-13  2:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-13  2:21 [PATCH 0/2] lib/crc16: unexport crc16_table and crc16_byte() Eric Biggers
2025-05-13  2:21 ` Eric Biggers [this message]
2025-05-13  7:52   ` [PATCH 1/2] w1: ds2406: use crc16() instead of crc16_byte() loop Krzysztof Kozlowski
2025-05-13  2:21 ` [PATCH 2/2] lib/crc16: unexport crc16_table and crc16_byte() Eric Biggers
2025-05-13  9:42 ` [PATCH 0/2] " Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250513022115.39109-2-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=ardb@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.