From patchwork Mon Nov 26 15:08:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 10698471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA43318A7 for ; Mon, 26 Nov 2018 15:10:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BC4629D2A for ; Mon, 26 Nov 2018 15:10:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F27929D2F; Mon, 26 Nov 2018 15:10:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 437BA29D2A for ; Mon, 26 Nov 2018 15:10:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbeK0CEV (ORCPT ); Mon, 26 Nov 2018 21:04:21 -0500 Received: from mga17.intel.com ([192.55.52.151]:40719 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbeK0CDa (ORCPT ); Mon, 26 Nov 2018 21:03:30 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2018 07:09:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,282,1539673200"; d="scan'208";a="90385145" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 26 Nov 2018 07:09:03 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id C65AA546; Mon, 26 Nov 2018 17:08:58 +0200 (EET) From: Andy Shevchenko To: Darren Hart , platform-driver-x86@vger.kernel.org, "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, Jonathan Cameron , Wolfram Sang , Mika Westerberg , linux-i2c@vger.kernel.org, Hans de Goede , Heikki Krogerus , linux-kernel@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v2 05/13] i2c: acpi: Return error pointers from i2c_acpi_new_device() Date: Mon, 26 Nov 2018 17:08:50 +0200 Message-Id: <20181126150858.16901-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181126150858.16901-1-andriy.shevchenko@linux.intel.com> References: <20181126150858.16901-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The caller would like to know the reason why the i2c_acpi_new_device() fails. For example, if adapter is not available, it might be in the future and we would like to re-probe the clients again. But at the same time we would like to bail out if the error seems unrecoverable, such as out of memory condition. To achieve this, return error pointer in some cases. Signed-off-by: Andy Shevchenko Reviewed-by: Hans de Goede --- drivers/i2c/i2c-core-acpi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index 32affd3fa8bd..af4b5bd5d973 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -387,6 +387,7 @@ struct notifier_block i2c_acpi_notifier = { * Also see i2c_new_device, which this function calls to create the i2c-client. * * Returns a pointer to the new i2c-client, or NULL if the adapter is not found. + * In some cases might return an error pointer. */ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, struct i2c_board_info *info) @@ -399,7 +400,7 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, adev = ACPI_COMPANION(dev); if (!adev) - return NULL; + return ERR_PTR(-ENODEV); memset(&lookup, 0, sizeof(lookup)); lookup.info = info; @@ -409,9 +410,11 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, ret = acpi_dev_get_resources(adev, &resource_list, i2c_acpi_fill_info, &lookup); acpi_dev_free_resource_list(&resource_list); + if (ret < 0) + return ERR_PTR(ret); - if (ret < 0 || !info->addr) - return NULL; + if (!info->addr) + return ERR_PTR(-EADDRNOTAVAIL); adapter = i2c_acpi_find_adapter_by_handle(lookup.adapter_handle); if (!adapter)