Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2831273pxv; Mon, 12 Jul 2021 03:02:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+DQVyrJtpMVKeMXtPSXqQsU0bIO9x02HzSsINkGVk957frdZyBhLy4aYFgDzT4kCe2ym2 X-Received: by 2002:a92:6902:: with SMTP id e2mr38221678ilc.275.1626084136989; Mon, 12 Jul 2021 03:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084136; cv=none; d=google.com; s=arc-20160816; b=MhGadBH0hy1bS1RjRfNn1+d4/f0lYc1hjrzJBc8MGqGSk52R3uA2JZ4ZdJc1LcMIp/ zQ9OdOMMRelooUTWejQGBkJsm5nGFuRcsLbH9bct5kjWkDZ7bjh/izTbZLWjXIsBygCD Kk76QVBf1t8pdraaEZtZc+taXcb+CSqMFGe/lzEBs2ReaS7cU0hdJvLURCUi935sIrIQ sr5LquvdVz75y6jD/JhusrEAQO5zEM+HdqWv2Zy4jpGBVypgOOtsCAoGEJ7/lH2a39Ae YTUCsMCco6HfuXKFkLkdtcOwZS9s3fHZKPNw9lWPX5fNKB5wLJvl/awKaCfESJQGFzZh j1xA== 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=ceB1s+S+Cj8Eshtv4S67a5eDE6a1Q/Ef/D37mTlobpg=; b=SyJGfkezqHSygFEkhtDVyAem7ytiPQNLB317pzR1mcbewEmlxeDgenPVMKKCzp5m1V 6seicGJC6olyTQJXAI32VMjt0gsTFQwIDFpzilirSyePmE30llEWx2X5mwSY9tMKDUxo rgEWrqMosOdtkWi1akDD5jzy4Se5ghjWxgvrV3El2hiaWFDCS4mW72OxWF/R7AfP7u4h L7GXqKMja1xC8zBLXTSvVpaqBaAe8ymYTGkULOGJrImLc+g4fCS30ybAhcwgsMm8C1Oe JgPXRpJPPGS0tquUGCIOh+I1j2jU7dvf2Aglju0oyw1hFGYabgz63D34+m2jl1kH6BTm YfiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FEr3hi5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si17008311iom.9.2021.07.12.03.02.05; Mon, 12 Jul 2021 03:02:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FEr3hi5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S243151AbhGLHPO (ORCPT + 99 others); Mon, 12 Jul 2021 03:15:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:50530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240327AbhGLGu4 (ORCPT ); Mon, 12 Jul 2021 02:50:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2D8F160FD8; Mon, 12 Jul 2021 06:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072488; bh=kuRrX1MUViblMIKwP9n3Eom3QwTmuiW3slBjQxbYPpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FEr3hi5ZaCv34UNwDi2Z4iE2sLcV7wi/mEInEdSZtW3c4Acb/ql+K1EiDNraxXr9F 0vT1Rs4QLVLMixbXx8blDnIkuDyhl2t+SiG8V253INl887V/BYHiLPmgimZdoJTyIJ dZZ9bZI/ZTDSAB2+Me1ovmwg7ND1yzHV4G5s8wIQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Sasha Levin Subject: [PATCH 5.10 477/593] firmware: stratix10-svc: Fix a resource leak in an error handling path Date: Mon, 12 Jul 2021 08:10:37 +0200 Message-Id: <20210712060942.862821131@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit d99247f9b542533ddbf87a3481a05473b8e48194 ] If an error occurs after a successful 'kfifo_alloc()' call, it must be undone by a corresponding 'kfifo_free()' call, as already done in the remove function. While at it, move the 'platform_device_put()' call to this new error handling path and explicitly return 0 in the success path. Fixes: b5dc75c915cd ("firmware: stratix10-svc: extend svc to support new RSU features") Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/0ca3f3ab139c53e846804455a1e7599ee8ae896a.1621621271.git.christophe.jaillet@wanadoo.fr Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/firmware/stratix10-svc.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c index 3aa489dba30a..2a7687911c09 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -1034,24 +1034,32 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) /* add svc client device(s) */ svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL); - if (!svc) - return -ENOMEM; + if (!svc) { + ret = -ENOMEM; + goto err_free_kfifo; + } svc->stratix10_svc_rsu = platform_device_alloc(STRATIX10_RSU, 0); if (!svc->stratix10_svc_rsu) { dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU); - return -ENOMEM; + ret = -ENOMEM; + goto err_free_kfifo; } ret = platform_device_add(svc->stratix10_svc_rsu); - if (ret) { - platform_device_put(svc->stratix10_svc_rsu); - return ret; - } + if (ret) + goto err_put_device; + dev_set_drvdata(dev, svc); pr_info("Intel Service Layer Driver Initialized\n"); + return 0; + +err_put_device: + platform_device_put(svc->stratix10_svc_rsu); +err_free_kfifo: + kfifo_free(&controller->svc_fifo); return ret; } -- 2.30.2