diff mbox series

rtc: fix a missing check of block data read

Message ID 20181226030911.72845-1-kjlu@umn.edu
State Accepted
Headers show
Series rtc: fix a missing check of block data read | expand

Commit Message

Kangjie Lu Dec. 26, 2018, 3:09 a.m. UTC
When i2c_smbus_read_i2c_block_data() fails, the read data in "buf" could
be incorrect and should not be used. The fix checks if
i2c_smbus_read_i2c_block_data fails, and if so, return its error code
upstream.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/rtc/rtc-hym8563.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alexandre Belloni Jan. 22, 2019, 6:04 p.m. UTC | #1
On 25/12/2018 21:09:11-0600, Kangjie Lu wrote:
> When i2c_smbus_read_i2c_block_data() fails, the read data in "buf" could
> be incorrect and should not be used. The fix checks if
> i2c_smbus_read_i2c_block_data fails, and if so, return its error code
> upstream.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/rtc/rtc-hym8563.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c
index e5ad527cb75e..d03f5d212eea 100644
--- a/drivers/rtc/rtc-hym8563.c
+++ b/drivers/rtc/rtc-hym8563.c
@@ -109,6 +109,8 @@  static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	}
 
 	ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);
+	if (ret < 0)
+		return ret;
 
 	tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK);
 	tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK);