linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: pcf2127: fix bug when reading alarm registers
@ 2022-02-08 16:29 Hugo Villeneuve
  2022-02-15 22:35 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Hugo Villeneuve @ 2022-02-08 16:29 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: hugo, Hugo Villeneuve, linux-rtc, linux-kernel

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

The first bug is that reading the 5 alarm registers results in a read
operation of 20 bytes. The reason is because the destination buffer is
defined as an array of "unsigned int", and we use the sizeof()
operator on this array to define the bulk read count.

The second bug is that the read value is invalid, because we are
indexing the destination buffer as integers (4 bytes), instead of
indexing it as u8.

Changing the destination buffer type to u8 fixes both problems.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 drivers/rtc/rtc-pcf2127.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 823abe2a7147..d88c0fdbe117 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -374,7 +374,8 @@ static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127)
 static int pcf2127_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
 	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
-	unsigned int buf[5], ctrl2;
+	u8 buf[5];
+	unsigned int ctrl2;
 	int ret;
 
 	ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2);
-- 
2.30.2


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

* Re: [PATCH] rtc: pcf2127: fix bug when reading alarm registers
  2022-02-08 16:29 [PATCH] rtc: pcf2127: fix bug when reading alarm registers Hugo Villeneuve
@ 2022-02-15 22:35 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2022-02-15 22:35 UTC (permalink / raw)
  To: Hugo Villeneuve, Alessandro Zummo
  Cc: Alexandre Belloni, Hugo Villeneuve, linux-rtc, linux-kernel

On Tue, 8 Feb 2022 11:29:07 -0500, Hugo Villeneuve wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> The first bug is that reading the 5 alarm registers results in a read
> operation of 20 bytes. The reason is because the destination buffer is
> defined as an array of "unsigned int", and we use the sizeof()
> operator on this array to define the bulk read count.
> 
> [...]

Applied, thanks!

[1/1] rtc: pcf2127: fix bug when reading alarm registers
      commit: 73ce05302007eece23a6acb7dc124c92a2209087

Best regards,
-- 
Alexandre Belloni <alexandre.belloni@bootlin.com>

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

end of thread, other threads:[~2022-02-15 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 16:29 [PATCH] rtc: pcf2127: fix bug when reading alarm registers Hugo Villeneuve
2022-02-15 22:35 ` 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).