rtc: bq4802: add error handling for devm_ioremap
authorZhouyang Jia <jiazhouyang09@gmail.com>
Tue, 12 Jun 2018 04:40:03 +0000 (12:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2018 06:38:13 +0000 (08:38 +0200)
[ Upstream commit 7874b919866ba91bac253fa219d3d4c82bb944df ]

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>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/rtc/rtc-bq4802.c

index bd170cb3361ce15e511a3a81f2ff1c06a5ed3bfe..5747a54cbd423e34c13e5f920ee7f8bce1cc2c50 100644 (file)
@@ -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 {