Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751429AbbLZKPx (ORCPT ); Sat, 26 Dec 2015 05:15:53 -0500 Received: from mout.web.de ([212.227.17.11]:50154 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751132AbbLZKPu (ORCPT ); Sat, 26 Dec 2015 05:15:50 -0500 Subject: [PATCH 1/3] IDE-ACPI: One function call less in ide_get_dev_handle() after error detection To: linux-ide@vger.kernel.org, "David S. Miller" References: <566ABCD9.1060404@users.sourceforge.net> <567E6799.5070802@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <567E68CE.7030503@users.sourceforge.net> Date: Sat, 26 Dec 2015 11:15:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <567E6799.5070802@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:hgNS7rQrHodLMLRUFwBFZLcwKaLZbvbDd7ZDDNI4whzCuUpuQSC n8CTms7F3kBWqlQGjM2arNmcHbGUtwqopws7Did8cEuM4kF9d0yqqlH0E1M+gQVVsWjnHhi 4s4R2UUNZF4nqB77XWj6F1X+JexOOEB5Snt2ZM9nkGE+9ClZSAaFZ5WYU0JPm/Do1asQ5jU /2NfVdhOdFLJEeZkV4IeQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:gdJKYQvjIqA=:NTap6ym9+39ngdn2BmCFVP DcPLFLctwkXdpexXoVpQlazHb+8vNBVBZpniisPiRtaQSwV6POB+CBQufDcU+xtQXRQ0X3kJi 7qiuNXRFw+6+MSwkj20g3nPlrN8XZKZXiVamGSZAX0Xmz1xoF4th8O6gHntH8IkMHved24euy LqTUgb9bveLHkdyQ3AIrca1IelONgABH5ywQ6Sqvv/uk/z8xn9dCmRYOfKiTQRYQ8MJpe6Sug FQIi7F0k901QEyR04RKPx+WRdcTiq84Dr/zInrEHloGhhkonEgGVh3wOOIrwqr3RCWKGZTg4o xgjcW3ltkUcz4vngJ7HYwLZJeW+FBNLEaQ1JhAsn3Mgud0z0QeCQW79NTPNf5mrkWFWjplBFB dvHeZJ8edfcJzajslo7y6aE1aP/k7FVAgKaWW5attQ/H3eEiIIWHFSCrMsq6ZjVmf3GoAbDev FhFinl2BzkeY6LEhnLxuXcrZi3yInYZ+1grkXRV4j9wF5aXY0cYhJCehZuYyBb0nx1xbQmL3V R7ICr4RfxGIOuNg8C4AemQA63BO+UAln9Sk8qFkPHYbJBJN3/wm++09hdNBn5sTTXid1g1Pj1 naWJ+O5GumIHqIE0W33u5IrHRoXOOQNFNWCjtAhGyNaWUEUqmckhAeqV5vzOWAjV2ZEyRRBM6 GLD3alpvP3hZn9fImsTd+6t8znamwj0YG7jfOQa+ChTGdMCuWbpTCVS8sEJwomz/8GaFssUXR bFBZlUa439nybXbRS7b8QhDYLIfA+rTxOXxHRFwUDrV586qsnqNsbsRLIrJzV0pAfVpr50Ia0 x0+K3nz Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2329 Lines: 76 From: Markus Elfring Date: Sat, 26 Dec 2015 10:01:36 +0100 The kfree() function was called in two cases by the ide_get_dev_handle() function during error handling even if the passed variable "dinfo" contained a null pointer. * Let us return directly if a call of the function "ACPI_HANDLE" or "acpi_get_object_info" failed. * Delete the explicit initialisation for the variables "dinfo" and "ret" at the beginning then. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/ide/ide-acpi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c index b694099..319b754 100644 --- a/drivers/ide/ide-acpi.c +++ b/drivers/ide/ide-acpi.c @@ -126,8 +126,8 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle, u64 addr; acpi_handle dev_handle; acpi_status status; - struct acpi_device_info *dinfo = NULL; - int ret = -ENODEV; + struct acpi_device_info *dinfo; + int ret; bus = pdev->bus->number; devnum = PCI_SLOT(pdev->devfn); @@ -140,13 +140,13 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle, dev_handle = ACPI_HANDLE(dev); if (!dev_handle) { DEBPRINT("no acpi handle for device\n"); - goto err; + return -ENODEV; } status = acpi_get_object_info(dev_handle, &dinfo); if (ACPI_FAILURE(status)) { DEBPRINT("get_object_info for device failed\n"); - goto err; + return -ENODEV; } if (dinfo && (dinfo->valid & ACPI_VALID_ADR) && dinfo->address == addr) { @@ -157,13 +157,14 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle, " address: %llu, should be %u\n", dinfo ? (unsigned long long)dinfo->address : -1ULL, (unsigned int)addr); - goto err; + ret = -ENODEV; + goto free_info; } DEBPRINT("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n", devnum, func, (unsigned long long)addr, *handle); ret = 0; -err: +free_info: kfree(dinfo); return ret; } -- 2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/