Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2238366pxb; Wed, 30 Mar 2022 20:19:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWhGbeUiYF4WGDfmFa5IcDb34AAFEsmEr+00BHiXYfInHPOzutfHQdx2d2v+4kwR83gnXt X-Received: by 2002:a17:90b:4c0a:b0:1c6:90be:1e03 with SMTP id na10-20020a17090b4c0a00b001c690be1e03mr3638420pjb.7.1648696789857; Wed, 30 Mar 2022 20:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648696789; cv=none; d=google.com; s=arc-20160816; b=jf+j4tYVMSPzuxHOozAmMfMIQG2tDEef/33efJTMp0bux31lSKMQGRjiYsPCVrS6+i VCqIpUqUHzYk80aIyLCZrmSiSSIZKKlalzjpWX8Jno3dgxe9ZoUrNrMG47ajLuXrbk9k 6riuLnx0AfBuodeL73SWuQ71MkQXyBGYewJr9E2iNc2EsnQMdS0qKDD7MdRL4nU3Adco Ct+vbgIBu3rtryqq2dteGkgjYPRk1A4w8mrphWM4jL1F8q7rJqvD73OdBL1hoQmyN/x8 cvMuwH866Qtwg5ujxvulsuTdDDhK64OaI57ePYODYGpfaiiXdI9ZTkyU/MzXA9lv3z1r 2Hdw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ym1YA9p/aXGppmVk2y9/m1seZgMe5DNSOgVkT3Ecvhg=; b=LNo10eS4XFDVrTL5uzfEi85qhxpzor6iB47oZMeGxocVsuV4Ov332b+5WnnHpuBk6d qd4Ga4OVyXWeb0C/3V+GvhJWqoSgF4y3kRc2vHEnj3dpBoue6Dx5gXhBWVNA9IzDolKa qiI+BrJ/TKbgq7akTSj2Db6Oz+fBp9IgpGHkggv5f7HXTm3BYk9lrT1Lf1NN7TzdkiKs l1N+34iAqFHTbhBFSJpI0oWE1jd+ZOzFCDaK+WikmuYhFZdZvy11g/12XipoEbwVDpaQ IQDfY+pyIC3jNPfUfx8HnZlRrwqgPri9DwNeM4E5nJD/IW1vES8kMK5QFavfwnSwNHvH RYHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=szzKjdLF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p7-20020a635b07000000b0038160c4545csi24801191pgb.115.2022.03.30.20.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:19:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=szzKjdLF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9AE111081B5; Wed, 30 Mar 2022 19:51:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344329AbiC3MBT (ORCPT + 99 others); Wed, 30 Mar 2022 08:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344796AbiC3Lxj (ORCPT ); Wed, 30 Mar 2022 07:53:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5AB927973D; Wed, 30 Mar 2022 04:49:40 -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 50B0761640; Wed, 30 Mar 2022 11:49:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7CE2C34115; Wed, 30 Mar 2022 11:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640979; bh=cmQjIDOiyu6i0WOxV+vP3qJn8wa2woRKYCESBKH7hvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=szzKjdLFw51xygWvZp84AG2D5Gve2l7CrmRA94s7VKh7WJ+ZniM1wpvr6SBP6Z96r 4TT8+LDu5SnUDllBBXt3aIJXg9dIyEkKhmJyi8PVla84ueyzDxsvMJJeNFc7QV+DV0 eoF4K6Zjrkr6Ks2/3SW69cjzAIom5HKYn2ucdSkUytMuvQPSTzhiPtLyxfe14ViMSR yYAI8vImHdGaEDymSvB0vqy+li0gW+mfEtzX/zmXCPqT07RMr8vkpQeEGG0qF7loDG cXFR8fItR0RcYYb8AXmYx4b6GlO9EpDHknxyDmLvpbP9fnBWr5BuZhd5NXWhFl/pIM WR01QBlqpal1A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Greg Kroah-Hartman , Arnd Bergmann , Sasha Levin , eric.y.miao@gmail.com, haojian.zhuang@gmail.com, linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.16 43/59] ARM: mmp: Fix failure to remove sram device Date: Wed, 30 Mar 2022 07:48:15 -0400 Message-Id: <20220330114831.1670235-43-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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