rtc: rtc-bq4802: add error handling for devm_ioremap

Message ID 1528778404-41456-1-git-send-email-jiazhouyang09@gmail.com
State Accepted
Headers show
Series
  • rtc: rtc-bq4802: add error handling for devm_ioremap
Related show

Commit Message

Zhouyang Jia June 12, 2018, 4:40 a.m.
When devm_ioremap fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling devm_ioremap.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/rtc/rtc-bq4802.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Alexandre Belloni June 20, 2018, 10:46 a.m. | #1
On 12/06/2018 12:40:03+0800, Zhouyang Jia wrote:
> When devm_ioremap fails, the lack of error-handling code may
> cause unexpected results.
> 
> This patch adds error-handling code after calling devm_ioremap.
> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
>  drivers/rtc/rtc-bq4802.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
Applied, thanks.

Patch

diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index bd170cb..5747a54 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -164,6 +164,10 @@  static int bq4802_probe(struct platform_device *pdev)
 	} else if (p->r->flags & IORESOURCE_MEM) {
 		p->regs = devm_ioremap(&pdev->dev, p->r->start,
 					resource_size(p->r));
+		if (!p->regs){
+			err = -ENOMEM;
+			goto out;
+		}
 		p->read = bq4802_read_mem;
 		p->write = bq4802_write_mem;
 	} else {