linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: ds2404: use hw endiannes variable
@ 2019-05-09  2:13 Nicholas Mc Guire
  2019-05-23 15:42 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2019-05-09  2:13 UTC (permalink / raw)
  To: Alessandro Zummo
  Cc: Alexandre Belloni, linux-rtc, linux-kernel, Nicholas Mc Guire

Converting from hardware to host endiannes was done using reassignment
to the same variable which makes sparse unhappy as it can not verify
the endiannes handling properly. To allow sparse to verify endiannes
handling an explicit __le32 is introduced. Note that this patch does
not change the generated binary (x86_64 and ppc64 binary diff).

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

Problem located by an experimental coccinelle script to locate
patters that make sparse unhappy (false positives):

on little-endian x86_64 sparse complains about:
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32
on big-endian ppc64 sparse complains about
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32
drivers/rtc/rtc-ds2404.c:187:16: warning: cast to restricted __le32

Patch was compiletested with:
 x86_64_defconfig + RTC_DRV_DS2404=m
 ppc64_defconfig + RTC_DRV_DS2404=m

in both cases applying the patch has no impact on the generated binary.

Patch is against 5.1 (localversion-next is next-20190508)

 drivers/rtc/rtc-ds2404.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 1e9f429..9df0c44 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -182,9 +182,10 @@ static void ds2404_enable_osc(struct device *dev)
 static int ds2404_read_time(struct device *dev, struct rtc_time *dt)
 {
 	unsigned long time = 0;
+	__le32 hw_time = 0;
 
-	ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
-	time = le32_to_cpu(time);
+	ds2404_read_memory(dev, 0x203, 4, (u8 *)&hw_time);
+	time = le32_to_cpu(hw_time);
 
 	rtc_time64_to_tm(time, dt);
 	return 0;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-23 15:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-09  2:13 [PATCH] rtc: ds2404: use hw endiannes variable Nicholas Mc Guire
2019-05-23 15:42 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).