From patchwork Fri Apr 6 14:23:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10326805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C77E56053F for ; Fri, 6 Apr 2018 14:25:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4FAD2953D for ; Fri, 6 Apr 2018 14:25:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A996D2953F; Fri, 6 Apr 2018 14:25:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 525F82953D for ; Fri, 6 Apr 2018 14:25:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756347AbeDFOZS (ORCPT ); Fri, 6 Apr 2018 10:25:18 -0400 Received: from osg.samsung.com ([64.30.133.232]:55000 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754402AbeDFOX3 (ORCPT ); Fri, 6 Apr 2018 10:23:29 -0400 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 18C2D32C9E; Fri, 6 Apr 2018 07:23:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vH-PZO_yT1vt; Fri, 6 Apr 2018 07:23:28 -0700 (PDT) Received: from smtp.s-opensource.com (177.17.251.195.dynamic.adsl.gvt.net.br [177.17.251.195]) by osg.samsung.com (Postfix) with ESMTPSA id 81DAD32C63; Fri, 6 Apr 2018 07:23:26 -0700 (PDT) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.90_1) (envelope-from ) id 1f4SGy-0008XE-CN; Fri, 06 Apr 2018 10:23:24 -0400 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab , Greg Kroah-Hartman , 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 Message-Id: <5963491651fe2385fa50cf9371cb826f640e91e8.1523024380.git.mchehab@s-opensource.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }