Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp922397pxb; Wed, 6 Apr 2022 04:22:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2ishpflGj9TlynVFo7u+pf2LNVsspZJOVDC4coAK+q0ZaQ5mfznrsj5m67r/028IfbyWc X-Received: by 2002:a17:90a:5296:b0:1ca:78cc:7172 with SMTP id w22-20020a17090a529600b001ca78cc7172mr9473672pjh.99.1649244161663; Wed, 06 Apr 2022 04:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649244161; cv=none; d=google.com; s=arc-20160816; b=vE8fOKFtKf7nQumdWxrHQQWaV7vKpDZB9XttALboR+dqMhjqw3BFfAo78BplBG/73o ufagNcrmMTRdVGo4gqHw8lTn5/CD5R4tzWHDfOLWc3A/neG9FqoMm0BrdLwo9fwJnL4L Mu39O2tGxbOzbkcv/m9vtXeS2gyNkWgYBU4fozd02NuceaBm7Z7dztjsoYukpKcfvYQN LCLb94lJiyT8A5ZzwfU+gcfBb9orlw8yv4KlhVL0HQ6sIvbQd1EllrpfchZAR3+HaxVV ETcao9cpXjG2YOcCpFdhgZe7hS79l8pUA77g2HeFWsAKUXgQZpRZQwfyOsutA5DzVdUr 3Eow== 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=ppVjJKTBfyOqiFYJ382Ny7HM5vBtucFaqZ71Xj07AYj3epJZF7mUAHmwNtKjvIcW86 ZBUXzGCdH1c3kbPbyL2LPfbqlJH1huA/ZNXiZb6CNyLSXPBvevpt92IxdlbDZR+zH9pq O+GL6WNhCL09nW8+q1oV6NkO09wN/qD7uACq9wqaw/P0GBjjmZH2muN8fRhNuexixISV yzvsr3spPlANOjf56cdQQO/t4VxejHtjLaM5MpUcLRxtepaLBSHgQHBIJiicXmFKCLef tKC2IAQeBnTD/XJv2+FFfG4mFTPmnuA2P+iUM1474gTST0tltBoUXNfu6fBB/5LKjH74 q6Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QzIsdLaj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n6-20020a63ee46000000b003816043ee1fsi16470687pgk.20.2022.04.06.04.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:22:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QzIsdLaj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CEF2E46C698; Wed, 6 Apr 2022 02:44:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837071AbiDFAoF (ORCPT + 99 others); Tue, 5 Apr 2022 20:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352351AbiDEKE3 (ORCPT ); Tue, 5 Apr 2022 06:04:29 -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 86FD4BA308; Tue, 5 Apr 2022 02:53:07 -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 CEED0616E7; Tue, 5 Apr 2022 09:53:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E32B8C385A1; Tue, 5 Apr 2022 09:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152386; bh=cmQjIDOiyu6i0WOxV+vP3qJn8wa2woRKYCESBKH7hvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QzIsdLajShIMVHAeDiWfgzaW9I9IelxJ91y3AmBtM9vn08Bv7SbvIEGpMVCYxT3GR Cu7IWfstP7UMkPkQyHVYuOutlmfDQiaomxc/TbIWH9t01rfjwvhyqp1tqWvgsZER2L K+kyiEWkUFcvLGDEBOj3vKckVq0UT5hKCrNQrt4s= 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.15 759/913] ARM: mmp: Fix failure to remove sram device Date: Tue, 5 Apr 2022 09:30:21 +0200 Message-Id: <20220405070402.583684463@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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