All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: unlisted-recipients:; (no To-header on input)@bombadil.infradead.org
Cc: Mauro Carvalho Chehab <mchehab@s-opensource.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org
Subject: [PATCH 03/21] media: davinci_vpfe: fix vpfe_ipipe_init() error handling
Date: Fri,  6 Apr 2018 10:23:04 -0400	[thread overview]
Message-ID: <5963491651fe2385fa50cf9371cb826f640e91e8.1523024380.git.mchehab@s-opensource.com> (raw)
In-Reply-To: <cover.1523024380.git.mchehab@s-opensource.com>
In-Reply-To: <cover.1523024380.git.mchehab@s-opensource.com>

As warned:
	drivers/staging/media/davinci_vpfe/dm365_ipipe.c:1834 vpfe_ipipe_init() error: we previously assumed 'res' could be null (see line 1797)

There's something wrong at vpfe_ipipe_init():

1) it caches the resourse_size() from from the first region
   and reuses to the second region;

2) the "res" var is overriden 3 times;

3) at free logic, it assumes that "res->start" is not
   overriden by platform_get_resource(pdev, IORESOURCE_MEM, 6),
   but that's not true, as it can even be NULL there.

This patch fixes the above issues by:

a) store the resources used by release_mem_region() on
   a separate var;

b) stop caching resource_size(), using the function where
   needed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
index dd0cfc79f50c..b3a193ddd778 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -1778,25 +1778,25 @@ vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev)
 	struct media_pad *pads = &ipipe->pads[0];
 	struct v4l2_subdev *sd = &ipipe->subdev;
 	struct media_entity *me = &sd->entity;
-	static resource_size_t  res_len;
-	struct resource *res;
+	struct resource *res, *memres;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
 	if (!res)
 		return -ENOENT;
 
-	res_len = resource_size(res);
-	res = request_mem_region(res->start, res_len, res->name);
-	if (!res)
+	memres = request_mem_region(res->start, resource_size(res), res->name);
+	if (!memres)
 		return -EBUSY;
-	ipipe->base_addr = ioremap_nocache(res->start, res_len);
+	ipipe->base_addr = ioremap_nocache(memres->start,
+					   resource_size(memres));
 	if (!ipipe->base_addr)
 		goto error_release;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 6);
 	if (!res)
 		goto error_unmap;
-	ipipe->isp5_base_addr = ioremap_nocache(res->start, res_len);
+	ipipe->isp5_base_addr = ioremap_nocache(res->start,
+						resource_size(res));
 	if (!ipipe->isp5_base_addr)
 		goto error_unmap;
 
@@ -1831,7 +1831,7 @@ vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev)
 error_unmap:
 	iounmap(ipipe->base_addr);
 error_release:
-	release_mem_region(res->start, res_len);
+	release_mem_region(memres->start, resource_size(memres));
 	return -ENOMEM;
 }
 
-- 
2.14.3

  parent reply	other threads:[~2018-04-06 14:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 14:23 [PATCH 00/21] Fix sparse/smatch errors on non-x86 drivers Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 01/21] media: davinci_vpfe: remove useless checks from ipipe Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 02/21] media: dm365_ipipe: remove an unused var Mauro Carvalho Chehab
2018-04-06 14:23 ` Mauro Carvalho Chehab [this message]
2018-10-09  4:46   ` [PATCH 03/21] media: davinci_vpfe: fix vpfe_ipipe_init() error handling Joel Fernandes
2018-10-11 16:56     ` Joel Fernandes
2018-04-06 14:23 ` [PATCH 04/21] media: davinci_vpfe: mark __iomem as such Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 05/21] media: davinci_vpfe: get rid of an unused var at dm365_isif.c Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 06/21] media: davinci_vpfe: vpfe_video: remove an unused var Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 07/21] media: davinci_vpfe: don't use kernel-doc markup for simple comments Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 08/21] media: davinci_vpfe: fix a typo for "default" Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 09/21] media: davinci_vpfe: cleanup ipipe_[g|s]_config logic Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 10/21] media: davinci_vpfe: fix __user annotations Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 11/21] media: si470x: fix __be16 annotations Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 12/21] media: isif: reorder a statement to match coding style Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 13/21] media: davinci: fix an inconsistent ident Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 14/21] media: mmp-driver: add needed __iomem marks to power_regs Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 15/21] media: vpbe_display: properly handle error case Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 16/21] media: vpbe_display: get rid of warnings Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 17/21] media: ispstat: use %p to print the address of a buffer Mauro Carvalho Chehab
2018-04-06 15:46   ` Laurent Pinchart
2018-04-06 16:24     ` Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 18/21] media: isppreview: fix __user annotations Mauro Carvalho Chehab
2018-04-06 15:54   ` Laurent Pinchart
2018-04-06 16:22     ` Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 19/21] media: fsl-viu: use %p to print pointers Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 20/21] media: fsl-viu: fix __iomem annotations Mauro Carvalho Chehab
2018-04-06 14:23 ` [PATCH 21/21] media: omap_vout: fix wrong identing Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5963491651fe2385fa50cf9371cb826f640e91e8.1523024380.git.mchehab@s-opensource.com \
    --to=mchehab@s-opensource.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.