Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3294567rwe; Mon, 29 Aug 2022 09:01:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7n4egP4RleqU/WQfYcSvdHPnPn08rT5sevuDlA3Y8KwcCTL1xhOlHQUDdSl6AJXXw5PLnX X-Received: by 2002:a17:90b:4c8c:b0:1fa:c44f:473a with SMTP id my12-20020a17090b4c8c00b001fac44f473amr19412175pjb.195.1661788909067; Mon, 29 Aug 2022 09:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661788909; cv=none; d=google.com; s=arc-20160816; b=m0Vv5QKXIKoFPrx61cOpuymvkSzIr/4hd8uvXqlVrAPvESyGp6XJToD/4aT25kfs9g 0Kkz5s86hFdMCOtWZKnhqNZrVzgxulu+t3brHX5aU3AH1F5WCBlN5GS0Gc/axfCF66Jw RRBB7UThPfw4uDe6ZikDLIcDl+BW2eAg9NUW53bgABMLkk4YTeDAXwF426T4rbHpmVPn lMR/v7gSijtPAD7w7XfM+/1qkZtrp3Bu/MRRVOoRtpsprRzYQyyYG4xbyoV3hIjNnU3K Dv90Ep2PeDjsy0SXuZRIMWiAkTIsMH42EuSnDJxSsKK4I+aEpVvqewReDB+5ex2Dpc9C E5kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eq1FVb6cEDkVIGuypfiBTD31IttuCoW0O83WdCHuymM=; b=m8SVE96hipigTSj35abnvSOJfwbnZv7vVbHAuT54ok+KTiCtksKWcMzhOvJ4lqm2l9 ZrqkpRkt2zMZRGCJa62lSXhdtOCB/9syHGdZGQqmUgALQSJ1S+L1rwiW/UdIuY9eLu4C WfreqrIbC5kgmLN0tZRgPlr3l23XRBGIRlZBtRNyM3GFaBzacplyPO9II1Vdw2Ddr+KW a9tVbG85EcB/M8O0PMfkG+ml3fvKPsnYzZX8g+O5PbfbtD9ubL9+gYs0cWcnVFXbuuYG B1gJR21YEvqBi1iZYNMyCqQLRpzeBHDmakzPn3kU2vAlaD2Rn48W1fPt4OaQaMmq3wEt zmaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a63d449000000b0041d8ca10b57si9611996pgj.223.2022.08.29.09.01.36; Mon, 29 Aug 2022 09:01:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiH2PVu (ORCPT + 99 others); Mon, 29 Aug 2022 11:21:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiH2PVt (ORCPT ); Mon, 29 Aug 2022 11:21:49 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ED356DAEA; Mon, 29 Aug 2022 08:21:47 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.0.0) id d3c77fd95de3eca7; Mon, 29 Aug 2022 17:21:44 +0200 Received: from kreacher.localnet (public-gprs523165.centertel.pl [31.61.162.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id D44B666D25B; Mon, 29 Aug 2022 17:21:43 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Andy Shevchenko , Linux PM , Dan Carpenter Subject: [PATCH v1] ACPI: PM: Fix NULL argument handling in acpi_device_get/set_power() Date: Mon, 29 Aug 2022 17:21:43 +0200 Message-ID: <12062887.O9o76ZdvQC@kreacher> In-Reply-To: <12036348.O9o76ZdvQC@kreacher> References: <12036348.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 31.61.162.222 X-CLIENT-HOSTNAME: public-gprs523165.centertel.pl X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekuddgkeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeefuddriedurdduiedvrddvvddvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepfedurdeiuddrudeivddrvddvvddphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghl rdhorhhgpdhrtghpthhtohepuggrnhdrtggrrhhpvghnthgvrhesohhrrggtlhgvrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki In principle, it should be valid to pass NULL as the ACPI device pointer to acpi_device_get_power() and acpi_device_set_power() and they both are expected to return -EINVAL in that case, but that has been broken recently by commit 62fcb99bdf10 ("ACPI: Drop parent field from struct acpi_device") which has caused the ACPI device pointer to be dereferenced in these functions before the NULL check. Fix that and while at it make acpi_device_set_power() only use the parent field if the target ACPI device object's ignore_parent flag in not set. Fixes: 62fcb99bdf10 ("ACPI: Drop parent field from struct acpi_device") Reported-by: Dan Carpenter Signed-off-by: Rafael J. Wysocki --- linux-next material. --- drivers/acpi/device_pm.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) Index: linux-pm/drivers/acpi/device_pm.c =================================================================== --- linux-pm.orig/drivers/acpi/device_pm.c +++ linux-pm/drivers/acpi/device_pm.c @@ -74,13 +74,15 @@ static int acpi_dev_pm_explicit_get(stru */ int acpi_device_get_power(struct acpi_device *device, int *state) { - struct acpi_device *parent = acpi_dev_parent(device); int result = ACPI_STATE_UNKNOWN; + struct acpi_device *parent; int error; if (!device || !state) return -EINVAL; + parent = acpi_dev_parent(device); + if (!device->flags.power_manageable) { /* TBD: Non-recursive algorithm for walking up hierarchy. */ *state = parent ? parent->power.state : ACPI_STATE_D0; @@ -159,7 +161,6 @@ static int acpi_dev_pm_explicit_set(stru */ int acpi_device_set_power(struct acpi_device *device, int state) { - struct acpi_device *parent = acpi_dev_parent(device); int target_state = state; int result = 0; @@ -192,13 +193,17 @@ int acpi_device_set_power(struct acpi_de return -ENODEV; } - if (!device->power.flags.ignore_parent && parent && - state < parent->power.state) { - acpi_handle_debug(device->handle, - "Cannot transition to %s for parent in %s\n", - acpi_power_state_string(state), - acpi_power_state_string(parent->power.state)); - return -ENODEV; + if (!device->power.flags.ignore_parent) { + struct acpi_device *parent; + + parent = acpi_dev_parent(device); + if (parent && state < parent->power.state) { + acpi_handle_debug(device->handle, + "Cannot transition to %s for parent in %s\n", + acpi_power_state_string(state), + acpi_power_state_string(parent->power.state)); + return -ENODEV; + } } /*