[PATCH AUTOSEL for-3.18 07/27] drm/sti: sti_vtg: Handle return NULL error from devm_ioremap_nocache

From: Levin, Alexander (Sasha Levin)
Date: Wed Nov 08 2017 - 15:56:44 EST


From: Arvind Yadav <arvind.yadav.cs@xxxxxxxxx>

[ Upstream commit 1ae0d5af347df224a6e76334683f13a96d915a44 ]

Here, If devm_ioremap_nocache will fail. It will return NULL.
Kernel can run into a NULL-pointer dereference. This error check
will avoid NULL pointer dereference.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@xxxxxxxxx>
Acked-by: Vincent Abriou <vincent.abriou@xxxxxx>
Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxx>
---
drivers/gpu/drm/sti/sti_vtg.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/sti/sti_vtg.c b/drivers/gpu/drm/sti/sti_vtg.c
index 740d6e347a62..b0fc11ec6ab7 100644
--- a/drivers/gpu/drm/sti/sti_vtg.c
+++ b/drivers/gpu/drm/sti/sti_vtg.c
@@ -303,6 +303,10 @@ static int vtg_probe(struct platform_device *pdev)
return -ENOMEM;
}
vtg->regs = devm_ioremap_nocache(dev, res->start, resource_size(res));
+ if (!vtg->regs) {
+ DRM_ERROR("failed to remap I/O memory\n");
+ return -ENOMEM;
+ }

np = of_parse_phandle(pdev->dev.of_node, "st,slave", 0);
if (np) {
--
2.11.0