public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hwmon@vger.kernel.org
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 2/5] rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L
Date: Sat, 26 Nov 2022 16:18:03 +0200	[thread overview]
Message-ID: <20221126141806.62205-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20221126141806.62205-1-andriy.shevchenko@linux.intel.com>

We are reading 10-bit value in a 16-bit register in LE format.
Make this explicit by using __le16 type for it and corresponding
conversion function.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/rtc/rtc-isl12022.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index 44058fa27277..bf1aa6f6560d 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -19,6 +19,8 @@
 #include <linux/regmap.h>
 #include <linux/hwmon.h>
 
+#include <asm/byteorder.h>
+
 /* ISL register offsets */
 #define ISL12022_REG_SC		0x00
 #define ISL12022_REG_MN		0x01
@@ -63,17 +65,16 @@ static umode_t isl12022_hwmon_is_visible(const void *data,
 static int isl12022_hwmon_read_temp(struct device *dev, long *mC)
 {
 	struct regmap *regmap = dev_get_drvdata(dev);
-	u8 temp_buf[2];
 	int temp, ret;
+	__le16 buf;
 
-	ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L,
-			       temp_buf, sizeof(temp_buf));
+	ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L, &buf, sizeof(buf));
 	if (ret)
 		return ret;
 	/*
 	 * Temperature is represented as a 10-bit number, unit half-Kelvins.
 	 */
-	temp = (temp_buf[1] << 8) | temp_buf[0];
+	temp = le16_to_cpu(buf);
 	temp *= 500;
 	temp -= 273000;
 
-- 
2.35.1


  reply	other threads:[~2022-11-26 14:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-26 14:18 [PATCH v1 1/5] rtc: isl12022: Get rid of unneeded private struct isl12022 Andy Shevchenko
2022-11-26 14:18 ` Andy Shevchenko [this message]
2022-11-29 14:13   ` [PATCH v1 2/5] rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L Rasmus Villemoes
2022-11-26 14:18 ` [PATCH v1 3/5] rtc: isl12022: Drop unneeded OF guards and of_match_ptr() Andy Shevchenko
2022-11-26 14:18 ` [PATCH v1 4/5] rtc: isl12022: Join string literals back Andy Shevchenko
2022-11-29 14:15   ` Rasmus Villemoes
2022-11-26 14:18 ` [PATCH v1 5/5] rtc: isl12022: sort header inclusion alphabetically Andy Shevchenko
2022-11-29 14:15   ` Rasmus Villemoes
2022-11-29 14:10 ` [PATCH v1 1/5] rtc: isl12022: Get rid of unneeded private struct isl12022 Rasmus Villemoes
2022-12-28  9:42   ` Andy Shevchenko

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=20221126141806.62205-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linux@roeck-us.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox