Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4200860ybl; Mon, 13 Jan 2020 09:31:13 -0800 (PST) X-Google-Smtp-Source: APXvYqymikEEB9P8CwpE7YkPw90zqSRl0fE5w0UJDE3PDpywbM2sxfXD2GfenFm+Cyw8iRAU55LW X-Received: by 2002:a54:4f14:: with SMTP id e20mr12964847oiy.84.1578936673580; Mon, 13 Jan 2020 09:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578936673; cv=none; d=google.com; s=arc-20160816; b=Pcs2IVaIh5CeUnAhlCp9YUs2QJDD6VSt8EbTw/fS6oEHMpozvkP2j8eerRg0ZnV6+5 pQ4tT7af2X2j52uG3qeF/6Y2s/vA3x9LDEAEUiEPda+D1QE5NDwo/ReV6u18Jpzy+tJf xKC9ccYcz76Q1iN8CnuAvr0rD/tLdTae4mMkepZgjhq2CZgsKtaBj3vChpiDmftkIIoa jdQ+JdvbNIvV1CXKh6jTlpdKEqo/IfCF3Y6VqZV5oHmRaCttkObWRat5UkWhtX92foXU odyfM/4yTrG9KwPVsFnYSL/0LoKwDDkFj3aapW2rTG8llI2nUE7ty7eRuGFKKRKVaH+c aDnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=BP1r7HFv2WsEj3QppgG1OeQrVFgjjK7ESVP9ZyofVwM=; b=OTMqAz7kr+WXT+c6NV/wGWv9qikwi5BIKScj6KImvnM0M2npgjLBtxyVM9ssMOQLR0 yrPVIm4/8I0KsnwyNodIjPPL492nPrMolvBd960d++AN6E3RAAdKEw46WBjdugutQyC/ HML/gcIYgC6ShYNz7m8NCtVyAPIp21TjhfQO8qkNfPp59B2UStmTijEYNa38//aHsst7 +42zfGgIUuu0N7AJXRIPZ2WWVWvtNH3GMKqZEBvkXWMfwOZlLNQEz7L0yGe+q+deFa1n +rYzXm4wAsV9MoiuWfHWkCSQCkZ+Ckt+dOSsX87NucfZAzbkUTPu18hN+L6/zu6KF/E0 d5tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gtQghRIf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s19si7558554otd.9.2020.01.13.09.31.01; Mon, 13 Jan 2020 09:31:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gtQghRIf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728674AbgAMRaC (ORCPT + 99 others); Mon, 13 Jan 2020 12:30:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:53302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726435AbgAMRaC (ORCPT ); Mon, 13 Jan 2020 12:30:02 -0500 Received: from localhost.localdomain (unknown [194.230.155.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57874206DA; Mon, 13 Jan 2020 17:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578936601; bh=yxdNHMBNa1z7mPo0Ki+HxaAbVu5m6892gO1e+zJHjGA=; h=From:To:Cc:Subject:Date:From; b=gtQghRIfG5gHQVy7sTT6AcZgKlpP4R+SHaXpnii03pqmgEZTYiQWe/7IE1sBAzyag E3pewk0ojo6QGFT2Ndv+IbskUV9KOnVPnZqxc2CVfAwqcZdoPQmxoP3eQuBxWmKYed x1iwBMvXBRcx1p5HSHXa7Y1R1aXnv4/HgVO/m2KU= From: Krzysztof Kozlowski To: Linus Walleij , Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH] i2c: iop3xx: Fix memory leak in probe error path Date: Mon, 13 Jan 2020 18:29:54 +0100 Message-Id: <20200113172954.5096-1-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When handling devm_gpiod_get_optional() errors, free the memory already allocated. This fixes Smatch warnings: drivers/i2c/busses/i2c-iop3xx.c:437 iop3xx_i2c_probe() warn: possible memory leak of 'new_adapter' drivers/i2c/busses/i2c-iop3xx.c:442 iop3xx_i2c_probe() warn: possible memory leak of 'new_adapter' Reported-by: kbuild test robot Reported-by: Dan Carpenter Signed-off-by: Krzysztof Kozlowski --- drivers/i2c/busses/i2c-iop3xx.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c index 38556381f4ca..2f8b8050a223 100644 --- a/drivers/i2c/busses/i2c-iop3xx.c +++ b/drivers/i2c/busses/i2c-iop3xx.c @@ -433,13 +433,17 @@ iop3xx_i2c_probe(struct platform_device *pdev) adapter_data->gpio_scl = devm_gpiod_get_optional(&pdev->dev, "scl", GPIOD_ASIS); - if (IS_ERR(adapter_data->gpio_scl)) - return PTR_ERR(adapter_data->gpio_scl); + if (IS_ERR(adapter_data->gpio_scl)) { + ret = PTR_ERR(adapter_data->gpio_scl); + goto free_both; + } adapter_data->gpio_sda = devm_gpiod_get_optional(&pdev->dev, "sda", GPIOD_ASIS); - if (IS_ERR(adapter_data->gpio_sda)) - return PTR_ERR(adapter_data->gpio_sda); + if (IS_ERR(adapter_data->gpio_sda)) { + ret = PTR_ERR(adapter_data->gpio_sda); + goto free_both; + } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { -- 2.17.1