From patchwork Mon Jan 23 17:10:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 646593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41863C05027 for ; Mon, 23 Jan 2023 17:15:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233378AbjAWRPX (ORCPT ); Mon, 23 Jan 2023 12:15:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233282AbjAWRPW (ORCPT ); Mon, 23 Jan 2023 12:15:22 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC152CC55; Mon, 23 Jan 2023 09:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674494114; x=1706030114; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/DBnlX2nHw8xdE1A7dfpSiRzHDfuI95hSDjM/i9Kzow=; b=YisKAmcEsusnIBZwQXx2fFjo+zxnt0nELBJj2KSgMBjiw9BdJKJN2FqT KGorQyMznTqkRI48vdkq3vBNUdn8hcvDur+eOoenkm8c5ZAKc9uLH1aQ9 7tcCmShxvqignrXj096zYOUw2B202QzOWmhBPSjH4ExHHTKSJaybK874l lSzR5rXEO0QPVAVAgneA/zmi0RUfikR1QeyPNWl53g8zrnKIv7/gNNDDh X2dtKTbGkR01EkdFL1qhzgVaGSmP0ICcLp8RWnIrerUPdpJ/fcElsDiZk Jiq6dGRP/4t03p6KDCFzeuMd6xAnEWV2Z49NCnk3Ex2KdkLKznR5thYI4 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="328182987" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="328182987" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 09:09:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="639261262" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="639261262" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 23 Jan 2023 09:09:38 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5A777119; Mon, 23 Jan 2023 19:10:14 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Hans de Goede , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: "Rafael J. Wysocki" , Len Brown , Robert Moore Subject: [PATCH v1 1/3] ACPI: video: Fix refcounting in apple_gmux_backlight_present() Date: Mon, 23 Jan 2023 19:10:04 +0200 Message-Id: <20230123171006.58274-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org acpi_dev_get_first_match_dev() gets ACPI device with the bumped refcount. The caller must drop it when it's done. Fix ACPI device refcounting in apple_gmux_backlight_present(). Fixes: 3cf3b7f012f3 ("ACPI: video: Fix Apple GMUX backlight detection") Signed-off-by: Andy Shevchenko --- drivers/acpi/video_detect.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index 65cec7bb6d96..0ccde0d4c527 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -114,12 +114,14 @@ static bool apple_gmux_backlight_present(void) { struct acpi_device *adev; struct device *dev; + bool ret; adev = acpi_dev_get_first_match_dev(GMUX_ACPI_HID, NULL, -1); if (!adev) return false; - dev = acpi_get_first_physical_node(adev); + dev = get_device(acpi_get_first_physical_node(adev)); + acpi_dev_put(adev); if (!dev) return false; @@ -127,7 +129,9 @@ static bool apple_gmux_backlight_present(void) * drivers/platform/x86/apple-gmux.c only supports old style * Apple GMUX with an IO-resource. */ - return pnp_get_resource(to_pnp_dev(dev), IORESOURCE_IO, 0) != NULL; + ret = pnp_get_resource(to_pnp_dev(dev), IORESOURCE_IO, 0) != NULL; + put_device(dev); + return ret; } /* Force to use vendor driver when the ACPI device is known to be From patchwork Mon Jan 23 17:10:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 645587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9D1BC05027 for ; Mon, 23 Jan 2023 17:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233242AbjAWROX (ORCPT ); Mon, 23 Jan 2023 12:14:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233075AbjAWROR (ORCPT ); Mon, 23 Jan 2023 12:14:17 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29FFF2313C; Mon, 23 Jan 2023 09:14:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674494056; x=1706030056; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F+6/rhKyOwDW70Iv9nyCUCzqIJXspwIUmmViGKg5jXI=; b=EwTWsP9L3bK1s7K/FsVxeHXS9au6fKNUX47pfD2/0EWd84bCZRT4+3fc HVaNW/Zszgm9TFiLo4n127duyby6Qcyle1IP3pMx0SEShVPKtS8qJIR4L HDDU+lsz0T4pVmFp9Lem4lkld50AB1XYj2gOkUfXZpAqHG1VOvESKFJXa s5ZaQ+GUSqt5Tz61+miFN8etjXL1FwJGdw7wH9tLI3CwX4EdzvT/AQrdT Ib5Aop29pZnwbcILUABiri3NF9sqwIx+OUdGOukPnHcuR7LMdxxSdNhk7 f+xNUNLOHnOCSBJBbQJXdY6KciFgfPF5vFhfwdARepiUbL1Kyx3k+Ckr1 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="324773374" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="324773374" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 09:09:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="694006131" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="694006131" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 23 Jan 2023 09:09:39 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 536C2154; Mon, 23 Jan 2023 19:10:15 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Hans de Goede , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: "Rafael J. Wysocki" , Len Brown , Robert Moore Subject: [PATCH v1 2/3] ACPI: utils: Add acpi_get_first_match_physical_node() Date: Mon, 23 Jan 2023 19:10:05 +0200 Message-Id: <20230123171006.58274-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123171006.58274-1-andriy.shevchenko@linux.intel.com> References: <20230123171006.58274-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org There are drivers that are using a logic that is combined in the offered acpi_get_first_match_physical_node(). The rationale to have this helper not only redunction of the lines of code, but improving the robustness by properly handling the reference counters on the error paths. Signed-off-by: Andy Shevchenko --- drivers/acpi/utils.c | 28 ++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 3 +++ include/linux/acpi.h | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 2ea14648a661..052e263d2246 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -965,6 +965,34 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) } EXPORT_SYMBOL(acpi_dev_get_first_match_dev); +/** + * acpi_get_first_match_physical_node - Return the physical node of the first match of ACPI device + * @hid: Hardware ID of the device. + * @uid: Unique ID of the device, pass NULL to not check _UID + * @hrv: Hardware Revision of the device, pass -1 to not check _HRV + * + * Return the physical node of the first match of ACPI device if a matching + * device was present at the moment of invocation, or NULL otherwise. + * + * The caller is responsible for invoking put_device() on the returned device. + * + * See additional information in acpi_dev_present() as well. + */ +struct device *acpi_get_first_match_physical_node(const char *hid, const char *uid, s64 hrv) +{ + struct acpi_device *adev; + struct device *dev; + + adev = acpi_dev_get_first_match_dev(hid, uid, hrv); + if (!adev) + return NULL; + + dev = get_device(acpi_get_first_physical_node(adev)); + acpi_dev_put(adev); + return dev; +} +EXPORT_SYMBOL(acpi_get_first_match_physical_node); + /** * acpi_reduced_hardware - Return if this is an ACPI-reduced-hw machine * diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 0584e9f6e339..e62af2f71362 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -777,6 +777,9 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); adev; \ adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) +struct device * +acpi_get_first_match_physical_node(const char *hid, const char *uid, s64 hrv); + static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev) { return adev ? to_acpi_device(get_device(&adev->dev)) : NULL; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4b12dad5a8a4..29bae77d819a 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -814,6 +814,12 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) return NULL; } +static inline struct device * +acpi_get_first_match_physical_node(const char *hid, const char *uid, s64 hrv) +{ + return NULL; +} + static inline bool acpi_reduced_hardware(void) { return false; From patchwork Mon Jan 23 17:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 646594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3CE3C05027 for ; Mon, 23 Jan 2023 17:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231515AbjAWROQ (ORCPT ); Mon, 23 Jan 2023 12:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231974AbjAWROP (ORCPT ); Mon, 23 Jan 2023 12:14:15 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18FFE227BA; Mon, 23 Jan 2023 09:14:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674494054; x=1706030054; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0U79zkIHIxmyTykAVQHhm+4844Ljl83bqkEvLyMecqU=; b=fYMdyCKRwJlhtKoKpc2crZWXpZRb94yxXdWPMTYIqaHCFTOeU7sg7MHr xtnNXiS3z07dXq6/0M3pyM+LIX25DT35+R0p7c6fa5I8yOvjAC2sMO8h/ trkOayi2NrSbARMv3CMxZKR8AU+ReW56u1IpfqJU4LAyXW0I7H6uGsmwD PFBgv4O6VzwIeKuI/wl488Ty5wz7pC8O0mhyH1tVjOIrbKBlcLgSCYVWE juE5+UKtMi1nfqdjzmrbIo5Cm8SyiaW5iSjNU1EeV+1GOuFjxrggyfa4O vvFJ8/zEFHaPsS3l1S+x6oPyMmJcLEPTyyh7lIeQg+3ayFBRsjb/xHZeR g==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="324773379" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="324773379" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 09:09:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="694006139" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="694006139" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 23 Jan 2023 09:09:40 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id D30A1165; Mon, 23 Jan 2023 19:10:15 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Hans de Goede , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: "Rafael J. Wysocki" , Len Brown , Robert Moore Subject: [PATCH v1 3/3] ACPI: video: Switch to use acpi_get_first_match_physical_node() Date: Mon, 23 Jan 2023 19:10:06 +0200 Message-Id: <20230123171006.58274-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123171006.58274-1-andriy.shevchenko@linux.intel.com> References: <20230123171006.58274-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Refactor the code to use acpi_get_first_match_physical_node(), which is currently open coded. Signed-off-by: Andy Shevchenko --- drivers/acpi/video_detect.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index 0ccde0d4c527..b23773347e67 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -112,16 +112,10 @@ static bool nvidia_wmi_ec_supported(void) static bool apple_gmux_backlight_present(void) { - struct acpi_device *adev; struct device *dev; bool ret; - adev = acpi_dev_get_first_match_dev(GMUX_ACPI_HID, NULL, -1); - if (!adev) - return false; - - dev = get_device(acpi_get_first_physical_node(adev)); - acpi_dev_put(adev); + dev = acpi_get_first_match_physical_node(GMUX_ACPI_HID, NULL, -1); if (!dev) return false;