From patchwork Thu Mar 12 13:32:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 11434267 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FD4092C for ; Thu, 12 Mar 2020 13:32:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AA48206E9 for ; Thu, 12 Mar 2020 13:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbgCLNc5 (ORCPT ); Thu, 12 Mar 2020 09:32:57 -0400 Received: from sauhun.de ([88.99.104.3]:42378 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbgCLNc5 (ORCPT ); Thu, 12 Mar 2020 09:32:57 -0400 Received: from localhost (p54B331A0.dip0.t-ipconnect.de [84.179.49.160]) by pokefinder.org (Postfix) with ESMTPSA id 950B12C1ECC; Thu, 12 Mar 2020 14:32:55 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-acpi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Mika Westerberg , Andy Shevchenko , Jarkko Nikula , Wolfram Sang , Geert Uytterhoeven Subject: [RFC PATCH] i2c: acpi: put device when verifying client fails Date: Thu, 12 Mar 2020 14:32:44 +0100 Message-Id: <20200312133244.9564-1-wsa@the-dreams.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Wolfram Sang i2c_verify_client() can fail, so we need to put the device when that happens. Fixes: 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications") Reported-by: Geert Uytterhoeven Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven Reviewed-by: Andy Shevchenko Acked-by: Mika Westerberg --- RFC because I don't know if it can be that the returned dev is not an i2c_client. Yet, since it can happen theoretically, I think we should have the checks. drivers/i2c/i2c-core-acpi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index 8f3dbc97a057..8b0ff780919b 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -394,9 +394,17 @@ EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle); static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev) { struct device *dev; + struct i2c_client *client; dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev); - return dev ? i2c_verify_client(dev) : NULL; + if (!dev) + return NULL; + + client = i2c_verify_client(dev); + if (!client) + put_device(dev); + + return client; } static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,