From patchwork Sat Dec 3 17:00:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9459703 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 6E75C6071C for ; Sat, 3 Dec 2016 17:03:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4371928387 for ; Sat, 3 Dec 2016 17:03:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 355A528399; Sat, 3 Dec 2016 17:03:03 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C3CE928387 for ; Sat, 3 Dec 2016 17:03:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDDgo-00031A-Qr; Sat, 03 Dec 2016 17:01:30 +0000 Received: from mout.web.de ([212.227.17.12]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDDgh-0002lp-Mg for linux-arm-kernel@lists.infradead.org; Sat, 03 Dec 2016 17:01:24 +0000 Received: from [192.168.1.2] ([77.182.219.73]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LdW7q-1cuUey3WXy-00ijsQ; Sat, 03 Dec 2016 18:00:54 +0100 Subject: [PATCH 1/2] ARM: mmp: Check return values from ioremap() and kstrdup() in sram_probe() To: linux-arm-kernel@lists.infradead.org, Eric Miao , Haojian Zhuang , Leo Yan , Russell King References: From: SF Markus Elfring Message-ID: Date: Sat, 3 Dec 2016 18:00:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:SJsrU/6AvTekK/Bj311DQStkNGxufvxS8pPVhYvfxyZPq8lmT6/ 9RNWCimXe0Va2gEcfjz0deeKvV1M6rfkRo3WBRhP7SQMQcdc4oj7rbZClJGXuNRrgIeEVuT jS0nmS4YYahhX/UMr2IzHj31WzNXgWQ2qlmFn6/QvCLpFbnvMdmzErg3rlfzCOq4oII0rge U23lkYepkZAgxCkl+GPqQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:M72h57vl0ws=:AuFlSLirHPI9Oz8WF1c2sr JXZrk6uIkv53ml/WkRtnUMBGkYNXYFdgfVrnzP1OPDnmmOK8R837jj1S8LvLHZUcwZvS3L2LX /rs8cKCT1wTr8taL45vv3taPifXluIGr3+/ozMMM39xKODSTzdieSvp4/iCEu2uTrzvcTVFRx kZ/y+LTG+vTtI+ZEpH0Eox6fZ/jQxiZKH8/8+DXzcxgRdCvQcg1MT2WVT5Ascyif3zTZDg61P 2XAt4G5+xKEahuNQ+7nJDUGrxd8BkmsetA9kW801goMieWclBgyHPPNDd9z/KG3mqnvRTkXoS rnszngi8ZCzw7ievK5cL1YArf2DNrTOqPQj1mtZfS84L/ik/VZmyOrb15yQ34PNty+CdF6zvs xH4gBhApgoF8+yj4W1fyJsISHspY92Heq0piZfdX5MplI+HdIxaM4EnuXbaGotohnQyOd3YjW wHlWMB266vmDR9ke7KZfNx2MdyMpp8kvOJJ21BvPcSXuDPwb+DehaGiLDArfvVAffo9gOXO49 ikumzvVLi9ZiFc7NEN/fIy596ha1lH9OLlCE7f3OrkwvYdBGhULfOVm6z4hsbCBeLVFIFPWib oazm06QXy78KNtWPrnmeLyMB0qBF8iucL05H5qCZ4qMFLwe6YztJmfTtQWCE4zOLGNB0Zaf3N kCHoptdAQVsrpFglYXr8cFhD1D0yrdW5eQf0s6S0fTKWGRWS3F4y0ZvUNG/SHKD6Q34XiMALo jZfJI5/cxfq5JNa4EVhIKh1bJUA2TzzjEflKnixDqP3Q5SwWPu0aVCjf9Mw240p/lG5tIs6XV +wsvPvs X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161203_090124_125391_D2FEFBB6 X-CRM114-Status: GOOD ( 10.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-janitors@vger.kernel.org, LKML Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 3 Dec 2016 17:26:32 +0100 Two return values were not checked before their further use so far. This issue was detected by using the Coccinelle software. * Add a bit of exception handling. * Adjust tump targets. Fixes: 3c7241bd36e2a618fe20c91f6c69cc20f2d981f2 ("ARM: mmp: add sram allocator") Signed-off-by: Markus Elfring --- arch/arm/mach-mmp/sram.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-mmp/sram.c b/arch/arm/mach-mmp/sram.c index bf5e64906e65..0fbfc2a42ab3 100644 --- a/arch/arm/mach-mmp/sram.c +++ b/arch/arm/mach-mmp/sram.c @@ -88,14 +88,24 @@ static int sram_probe(struct platform_device *pdev) info->sram_phys = (phys_addr_t)res->start; info->sram_size = resource_size(res); info->sram_virt = ioremap(info->sram_phys, info->sram_size); + if (!info->sram_virt) { + ret = -ENOMEM; + goto out; + } + info->pool_name = kstrdup(pdata->pool_name, GFP_KERNEL); + if (!info->pool_name) { + ret = -ENOMEM; + goto unmap_io; + } + info->granularity = pdata->granularity; info->gpool = gen_pool_create(ilog2(info->granularity), -1); if (!info->gpool) { dev_err(&pdev->dev, "create pool failed\n"); ret = -ENOMEM; - goto create_pool_err; + goto free_name; } ret = gen_pool_add_virt(info->gpool, (unsigned long)info->sram_virt, @@ -117,9 +127,10 @@ static int sram_probe(struct platform_device *pdev) add_chunk_err: gen_pool_destroy(info->gpool); -create_pool_err: - iounmap(info->sram_virt); +free_name: kfree(info->pool_name); +unmap_io: + iounmap(info->sram_virt); out: kfree(info); return ret;