Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1404732pxj; Fri, 21 May 2021 13:26:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcEi9WloitANLwW5mDFUOotdEAdMFIssn9pPqBfyKC7JWgQEKbEIYweTciInOf4kWWpY+7 X-Received: by 2002:a05:6402:1544:: with SMTP id p4mr13039800edx.341.1621628806913; Fri, 21 May 2021 13:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621628806; cv=none; d=google.com; s=arc-20160816; b=wHCOMrXz6iFESmarNxjIVS59er97aumcdCpBUMsB+ucB7cwMuwlAvv4hXGSe3PCyYK cU5tQWFsi0DuhVmu1YR/v1S0xZxhBiNacAbnEnLv6lDzLvIK0T7FRou1vlZ73UTkxwJt RxrcZxze8UIAetvWf1U+0bNs+o58vEDpJhrGViLJvD1EJOx5g6GQNSnS/uc5qxPraaWy ygwKcmHDUx99NKzN8MN4x3pw1phF4xG50ya1rc6YE5x+XNA1/yz6M9CJrRm0Qs13d1ot lOdaK6CgM1IEMwIA3zea1S0JkWS9SdLGKelTQz5qk24rEYcAoeCJFzAryG+MMWK7ypAO fjeQ== 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 :message-id:date:subject:cc:to:from; bh=+ovC5V9a06ZtyldXX574L79Wg8wk7KmolRKmEEiA17c=; b=RjlnWEJADRt7gXtrh02HYmmT9a+Hr3nOPVEM/PM+gAffthfHI3+WNQNWoIkAAHR2JT 5swN/bAqk9U0c1NrjlM5CSwcwgqpagrZ5GbOtSyYr77lZAaWnADzU9SXUuK4jp2ZL4QC +2z7g+8NiVAPUpIO/U+0bDcfhFYLCIOaI6Ji7ZtvfBdu7UtJjjzdbV2TKF5wYKaQYdvy OYeiMLEPgGWHAkx20k5oHlKcbhCI4PJM+uQ4hSzb79cKnm1Y/4/kmnKwTsn+CAuMkoE2 S2g6VD60UEz02NL4h5zOhYWpYq7HvlYWDCduvHehhOLfTQXtfuCu8evCIOoDxZ4xVpFG 8f1A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c14si5834760edv.258.2021.05.21.13.26.23; Fri, 21 May 2021 13:26:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238821AbhEUSXn (ORCPT + 99 others); Fri, 21 May 2021 14:23:43 -0400 Received: from smtp12.smtpout.orange.fr ([80.12.242.134]:36031 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232323AbhEUSXm (ORCPT ); Fri, 21 May 2021 14:23:42 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d35 with ME id 7WNG2500221Fzsu03WNGpn; Fri, 21 May 2021 20:22:17 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 21 May 2021 20:22:17 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: richard.gong@linux.intel.com, gregkh@linuxfoundation.org, atull@kernel.org Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] firmware: stratix10-svc: Fix a resource leak in an error handling path Date: Fri, 21 May 2021 20:22:15 +0200 Message-Id: <0ca3f3ab139c53e846804455a1e7599ee8ae896a.1621621271.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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