Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp687186pxb; Tue, 5 Apr 2022 18:48:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2ZJlVmMggsw2EJ3IQ3FbHhmxchQf1r8xqfCNRClNDFgVPOLym0lTWijKxn25zz35GsWAF X-Received: by 2002:a63:e817:0:b0:399:58c8:c3f0 with SMTP id s23-20020a63e817000000b0039958c8c3f0mr5126332pgh.468.1649209723491; Tue, 05 Apr 2022 18:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649209723; cv=none; d=google.com; s=arc-20160816; b=ZKp2Yd7kJmJmOxo99gwiTV5HiSZEEKUeUF/iNVvIE3J0TUQBEDb9HndD1oGKj2kAP9 V02P92ztSNgu3hS3AL4MQLJqxO41Q5zVOFiPrmWhiv7D8F4m820S4UIVqyWShjvddAuL VMjjnITNTJ2WR9noRvp7Rqd0dUE/C1kjZucaENDpHS3x5xvi6C0BG42s9rnl+ct/b/tj 7eTkH8YARTX2luC8KGVL2cRRvHyFWmB1E9leH/rNMoj1E9r1wGOh+zs4B7xqJfpBI/sP SQ9+S0GTC62tzhDedmWsFEqTZMnhcgj4o8C7k2EfbfZ0DVji4M+IvXt1KRHhTuvwrrFm GbrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ym1YA9p/aXGppmVk2y9/m1seZgMe5DNSOgVkT3Ecvhg=; b=xerfzN5fNrmIDFhhu8pyPSGmiRZM4CRSDM52fhEzfXUr02ed6yz5EaFntMJf8Ow2WF mx+gXwLh2Wge50+fRuwO+7tFztAhR2s3p6kpMzbL8tRUc83lO8xw5Cm/CZKUKG9AAII+ M2tk4wzlEd8qzuOQOND/UnQKVYhS0cCqykBzymuqGyYSsmt3YZW7P7+3xky9Do2YgmVh QwQyLZRAApi7XDqJ57ze5b9/LFRODhmEp/8l77Xq3saNCom6+GaUavC5of1nfp9v/jNg ox7l4BqqGg6JGXOa4ttCC0NK3SES6NoEUTvNew9DTN9rqSmjofZxZ583x093WemifZ8j nz1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FE5HcRJs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a17090a684400b001ca9b2f1131si3483314pjm.141.2022.04.05.18.48.27; Tue, 05 Apr 2022 18:48:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FE5HcRJs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383723AbiDENbQ (ORCPT + 99 others); Tue, 5 Apr 2022 09:31:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345660AbiDEJWz (ORCPT ); Tue, 5 Apr 2022 05:22:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B1C0506CA; Tue, 5 Apr 2022 02:11:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D09CF615E4; Tue, 5 Apr 2022 09:11:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E74F1C385A2; Tue, 5 Apr 2022 09:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149893; bh=cmQjIDOiyu6i0WOxV+vP3qJn8wa2woRKYCESBKH7hvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FE5HcRJslkZg+oi3VoErQLv7pWfbxjbKn+EKaTymJKnMiKhtQJn/ajNNfAnzHFqDe qVX7srfTob7oE88LZxnSOL52Fpuwe5hCKdfBAFZsLSSWYrBEOdWBavdlT6KhKtmLzH 970fII7aZp22xmDTJ/9wdDdE4bMWrl5yxMok7M78= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Arnd Bergmann , Sasha Levin Subject: [PATCH 5.16 0841/1017] ARM: mmp: Fix failure to remove sram device Date: Tue, 5 Apr 2022 09:29:14 +0200 Message-Id: <20220405070419.204610040@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Uwe Kleine-König [ Upstream commit 4036b29a146b2749af3bb213b003eb69f3e5ecc4 ] Make sure in .probe() to set driver data before the function is left to make it possible in .remove() to undo the actions done. This fixes a potential memory leak and stops returning an error code in .remove() that is ignored by the driver core anyhow. Signed-off-by: Uwe Kleine-König Reviewed-by: Greg Kroah-Hartman Signed-off-by: Arnd Bergmann Signed-off-by: Sasha Levin --- arch/arm/mach-mmp/sram.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/arm/mach-mmp/sram.c b/arch/arm/mach-mmp/sram.c index 6794e2db1ad5..ecc46c31004f 100644 --- a/arch/arm/mach-mmp/sram.c +++ b/arch/arm/mach-mmp/sram.c @@ -72,6 +72,8 @@ static int sram_probe(struct platform_device *pdev) if (!info) return -ENOMEM; + platform_set_drvdata(pdev, info); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(&pdev->dev, "no memory resource defined\n"); @@ -107,8 +109,6 @@ static int sram_probe(struct platform_device *pdev) list_add(&info->node, &sram_bank_list); mutex_unlock(&sram_lock); - platform_set_drvdata(pdev, info); - dev_info(&pdev->dev, "initialized\n"); return 0; @@ -127,17 +127,19 @@ static int sram_remove(struct platform_device *pdev) struct sram_bank_info *info; info = platform_get_drvdata(pdev); - if (info == NULL) - return -ENODEV; - mutex_lock(&sram_lock); - list_del(&info->node); - mutex_unlock(&sram_lock); + if (info->sram_size) { + mutex_lock(&sram_lock); + list_del(&info->node); + mutex_unlock(&sram_lock); + + gen_pool_destroy(info->gpool); + iounmap(info->sram_virt); + kfree(info->pool_name); + } - gen_pool_destroy(info->gpool); - iounmap(info->sram_virt); - kfree(info->pool_name); kfree(info); + return 0; } -- 2.34.1