From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C9A4C83000 for ; Wed, 29 Apr 2020 17:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5776820757 for ; Wed, 29 Apr 2020 17:42:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgD2Rmu (ORCPT ); Wed, 29 Apr 2020 13:42:50 -0400 Received: from smtp03.smtpout.orange.fr ([80.12.242.125]:40896 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbgD2Rmu (ORCPT ); Wed, 29 Apr 2020 13:42:50 -0400 Received: from [192.168.42.210] ([93.22.38.239]) by mwinf5d58 with ME id Yhig2200R59bE5H03hig2Q; Wed, 29 Apr 2020 19:42:48 +0200 X-ME-Helo: [192.168.42.210] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 29 Apr 2020 19:42:48 +0200 X-ME-IP: 93.22.38.239 Subject: Re: [PATCH] video: fbdev: pxa3xx_gcu: Fix some resource leak in an error handling path in 'pxa3xx_gcu_probe()' To: Dan Carpenter Cc: b.zolnierkie@samsung.com, gregkh@linuxfoundation.org, mpe@ellerman.id.au, zhenzhong.duan@gmail.com, arnd@arndb.de, tglx@linutronix.de, eric.y.miao@gmail.com, daniel@caiaq.de, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <20200429043438.96212-1-christophe.jaillet@wanadoo.fr> <20200429122538.GO2014@kadam> From: Christophe JAILLET Message-ID: <0db91149-fa85-6ec3-1787-d5effd41a1b9@wanadoo.fr> Date: Wed, 29 Apr 2020 19:42:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200429122538.GO2014@kadam> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 29/04/2020 à 14:25, Dan Carpenter a écrit : > On Wed, Apr 29, 2020 at 06:34:38AM +0200, Christophe JAILLET wrote: >> If an error occurs in the loop where we call 'pxa3xx_gcu_add_buffer()', >> any resource already allocated should be freed. >> >> In order to fix it, add a call to 'pxa3xx_gcu_free_buffers()' in the error >> handling path, as already done in the remove function. >> >> Fixes: 364dbdf3b6c3 ("video: add driver for PXA3xx 2D graphics accelerator") >> Signed-off-by: Christophe JAILLET >> --- >> drivers/video/fbdev/pxa3xx-gcu.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c >> index 4279e13a3b58..68d9c7a681d4 100644 >> --- a/drivers/video/fbdev/pxa3xx-gcu.c >> +++ b/drivers/video/fbdev/pxa3xx-gcu.c >> @@ -675,6 +675,7 @@ static int pxa3xx_gcu_probe(struct platform_device *pdev) >> >> err_disable_clk: >> clk_disable_unprepare(priv->clk); >> + pxa3xx_gcu_free_buffers(dev, priv); > The error handling in this function makes no sense and is buggy. It > should be that it unwinds in the reverse order from the allocation. The > goto should be "goto free_most_recently_allocated_resource;". Since the > unwind is done in the wrong order it causes a couple bugs. > > These buffers are the last thing which we allocated so they should be > the first thing which we free. In this case, calling > pxa3xx_gcu_free_buffers() before the buffers are allocated is confusing > but harmless. The clk_disable_unprepare() is done on some paths where > the clock was not enabled and that will trigger a WARN() so that's a > bug. Syzcaller will complain and if you have reboot on WARN then it's > annoying. > > The second bug is that we don't deregister the misc device or release > the DMA memory on failure when we allocate the buffers in the loop. > > regards, > dan carpenter > Agreed. I've been a little too fast on this one. I'll update it. Thx for the review. CJ From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christophe JAILLET Date: Wed, 29 Apr 2020 17:42:40 +0000 Subject: Re: [PATCH] video: fbdev: pxa3xx_gcu: Fix some resource leak in an error handling path in 'pxa3xx_gc Message-Id: <0db91149-fa85-6ec3-1787-d5effd41a1b9@wanadoo.fr> List-Id: References: <20200429043438.96212-1-christophe.jaillet@wanadoo.fr> <20200429122538.GO2014@kadam> In-Reply-To: <20200429122538.GO2014@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: Dan Carpenter Cc: linux-fbdev@vger.kernel.org, eric.y.miao@gmail.com, arnd@arndb.de, b.zolnierkie@samsung.com, gregkh@linuxfoundation.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, zhenzhong.duan@gmail.com, daniel@caiaq.de, mpe@ellerman.id.au, tglx@linutronix.de Le 29/04/2020 à 14:25, Dan Carpenter a écrit : > On Wed, Apr 29, 2020 at 06:34:38AM +0200, Christophe JAILLET wrote: >> If an error occurs in the loop where we call 'pxa3xx_gcu_add_buffer()', >> any resource already allocated should be freed. >> >> In order to fix it, add a call to 'pxa3xx_gcu_free_buffers()' in the error >> handling path, as already done in the remove function. >> >> Fixes: 364dbdf3b6c3 ("video: add driver for PXA3xx 2D graphics accelerator") >> Signed-off-by: Christophe JAILLET >> --- >> drivers/video/fbdev/pxa3xx-gcu.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c >> index 4279e13a3b58..68d9c7a681d4 100644 >> --- a/drivers/video/fbdev/pxa3xx-gcu.c >> +++ b/drivers/video/fbdev/pxa3xx-gcu.c >> @@ -675,6 +675,7 @@ static int pxa3xx_gcu_probe(struct platform_device *pdev) >> >> err_disable_clk: >> clk_disable_unprepare(priv->clk); >> + pxa3xx_gcu_free_buffers(dev, priv); > The error handling in this function makes no sense and is buggy. It > should be that it unwinds in the reverse order from the allocation. The > goto should be "goto free_most_recently_allocated_resource;". Since the > unwind is done in the wrong order it causes a couple bugs. > > These buffers are the last thing which we allocated so they should be > the first thing which we free. In this case, calling > pxa3xx_gcu_free_buffers() before the buffers are allocated is confusing > but harmless. The clk_disable_unprepare() is done on some paths where > the clock was not enabled and that will trigger a WARN() so that's a > bug. Syzcaller will complain and if you have reboot on WARN then it's > annoying. > > The second bug is that we don't deregister the misc device or release > the DMA memory on failure when we allocate the buffers in the loop. > > regards, > dan carpenter > Agreed. I've been a little too fast on this one. I'll update it. Thx for the review. CJ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3F0AC83006 for ; Thu, 30 Apr 2020 07:32:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4B3D20757 for ; Thu, 30 Apr 2020 07:32:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4B3D20757 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=wanadoo.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 81D636EB56; Thu, 30 Apr 2020 07:32:26 +0000 (UTC) Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by gabe.freedesktop.org (Postfix) with ESMTPS id C669A897D0 for ; Wed, 29 Apr 2020 17:42:50 +0000 (UTC) Received: from [192.168.42.210] ([93.22.38.239]) by mwinf5d58 with ME id Yhig2200R59bE5H03hig2Q; Wed, 29 Apr 2020 19:42:48 +0200 X-ME-Helo: [192.168.42.210] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 29 Apr 2020 19:42:48 +0200 X-ME-IP: 93.22.38.239 Subject: Re: [PATCH] video: fbdev: pxa3xx_gcu: Fix some resource leak in an error handling path in 'pxa3xx_gcu_probe()' To: Dan Carpenter References: <20200429043438.96212-1-christophe.jaillet@wanadoo.fr> <20200429122538.GO2014@kadam> From: Christophe JAILLET Message-ID: <0db91149-fa85-6ec3-1787-d5effd41a1b9@wanadoo.fr> Date: Wed, 29 Apr 2020 19:42:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200429122538.GO2014@kadam> Content-Language: en-US X-Mailman-Approved-At: Thu, 30 Apr 2020 07:31:56 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, eric.y.miao@gmail.com, arnd@arndb.de, b.zolnierkie@samsung.com, gregkh@linuxfoundation.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, zhenzhong.duan@gmail.com, daniel@caiaq.de, mpe@ellerman.id.au, tglx@linutronix.de Content-Transfer-Encoding: base64 Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" TGUgMjkvMDQvMjAyMCDDoCAxNDoyNSwgRGFuIENhcnBlbnRlciBhIMOpY3JpdMKgOgo+IE9uIFdl ZCwgQXByIDI5LCAyMDIwIGF0IDA2OjM0OjM4QU0gKzAyMDAsIENocmlzdG9waGUgSkFJTExFVCB3 cm90ZToKPj4gSWYgYW4gZXJyb3Igb2NjdXJzIGluIHRoZSBsb29wIHdoZXJlIHdlIGNhbGwgJ3B4 YTN4eF9nY3VfYWRkX2J1ZmZlcigpJywKPj4gYW55IHJlc291cmNlIGFscmVhZHkgYWxsb2NhdGVk IHNob3VsZCBiZSBmcmVlZC4KPj4KPj4gSW4gb3JkZXIgdG8gZml4IGl0LCBhZGQgYSBjYWxsIHRv ICdweGEzeHhfZ2N1X2ZyZWVfYnVmZmVycygpJyBpbiB0aGUgZXJyb3IKPj4gaGFuZGxpbmcgcGF0 aCwgYXMgYWxyZWFkeSBkb25lIGluIHRoZSByZW1vdmUgZnVuY3Rpb24uCj4+Cj4+IEZpeGVzOiAz NjRkYmRmM2I2YzMgKCJ2aWRlbzogYWRkIGRyaXZlciBmb3IgUFhBM3h4IDJEIGdyYXBoaWNzIGFj Y2VsZXJhdG9yIikKPj4gU2lnbmVkLW9mZi1ieTogQ2hyaXN0b3BoZSBKQUlMTEVUIDxjaHJpc3Rv cGhlLmphaWxsZXRAd2FuYWRvby5mcj4KPj4gLS0tCj4+ICAgZHJpdmVycy92aWRlby9mYmRldi9w eGEzeHgtZ2N1LmMgfCAxICsKPj4gICAxIGZp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