From patchwork Sun Jan 9 13:20:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12707776 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 756ADC433F5 for ; Sun, 9 Jan 2022 13:23:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=A9jaZphLZ77jcft9L1zeurKlY/FxUNqoyq1Lb2Uh8bU=; b=LZtn23TslKlojh aODUClYOtvE5mMdUDC7NJG0m/kG65NUjYBFkYPwGfH0CjTG+SpYNQ+vuEoK9IYLlNXUuAXHKUBQGr FkI8sK5I6uYLNt6op9WLT44CHOceVQ6d43Ad5UL8SZ426LEAyl6XI66h2JkxsJ9e+sZURRFvNEViI 7akv5yeMLgKlDPGTvJC6Ld5mhegW/MCZBUhffUFOwt3LLPUj0DpUrcIxrfUCZ2Yr95Fr4GJDV44kN 7zCfCULEX+FTZ5yzliM04GjIzPWhBFcYLKBTskvbJnJJ3KldT9a6xuAKPPUJH2cQitan38C+qE6/j etcx89Dc96Tzbah0E2vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6Y90-007sUe-Kg; Sun, 09 Jan 2022 13:21:58 +0000 Received: from smtp09.smtpout.orange.fr ([80.12.242.131] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6Y8w-007sTe-42 for linux-arm-kernel@lists.infradead.org; Sun, 09 Jan 2022 13:21:55 +0000 Received: from pop-os.home ([90.11.185.88]) by smtp.orange.fr with ESMTPA id 6Y8inCULaUujj6Y8inIUhA; Sun, 09 Jan 2022 14:21:46 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 09 Jan 2022 14:21:46 +0100 X-ME-IP: 90.11.185.88 From: Christophe JAILLET To: Jeremy Kerr , Joel Stanley , Alistar Popple , Eddie James , Andrew Jeffery , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , Guenter Roeck , linux-fsi@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org Subject: [PATCH v2] fsi: Aspeed: Fix a potential double free Date: Sun, 9 Jan 2022 14:20:35 +0100 Message-Id: <3b5c9b693749a956b525c54bed0eeac9f958b8e8.1641734402.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220109_052154_352958_9FB3B8A7 X-CRM114-Status: GOOD ( 12.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A struct device can never be devm_alloc()'ed. Here, it is embedded in "struct fsi_master", and "struct fsi_master" is embedded in "struct fsi_master_aspeed". Since "struct device" is embedded, the data structure embedding it must be released with the release function, as is already done here. So use kzalloc() instead of devm_kzalloc() when allocating "aspeed". This prevent a potential double free(). Fixes: 606397d67f41 ("fsi: Add ast2600 master driver") Suggested-by: Greg KH Suggested-by: Guenter Roeck Signed-off-by: Christophe JAILLET --- v2: Keep the release function which is correct s/devm_kzalloc()/kzalloc()/ instead --- drivers/fsi/fsi-master-aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c index 8606e55c1721..ae6319818b14 100644 --- a/drivers/fsi/fsi-master-aspeed.c +++ b/drivers/fsi/fsi-master-aspeed.c @@ -542,7 +542,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) return rc; } - aspeed = devm_kzalloc(&pdev->dev, sizeof(*aspeed), GFP_KERNEL); + aspeed = kzalloc(sizeof(*aspeed), GFP_KERNEL); if (!aspeed) return -ENOMEM;