From patchwork Fri Jan 24 09:31:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 232909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DBA2C32771 for ; Fri, 24 Jan 2020 11:30:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8A71222C2 for ; Fri, 24 Jan 2020 11:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865429; bh=FqMITQzpPmnKmgUK//ibo6+YIPZyhuZ0wjCpj8u/7n4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Y1MIC8N+1mtsqkWm9lieQtFMrY713UHu/iZZu4b7eOgmxg4jiLpNyJ5cgu+nGRu7u M8DX1bS1TOW+sJ/tUNNA4VYbTFlzM2abPDfMBNfxoL0cCAQVwiHd2AZtOgWIZh6Dn6 AOXHs7muZp3+pxy56TW/Co+6RxaCz0uRgbDq5NVs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404237AbgAXLa3 (ORCPT ); Fri, 24 Jan 2020 06:30:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:48144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404236AbgAXLa2 (ORCPT ); Fri, 24 Jan 2020 06:30:28 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A4F62077C; Fri, 24 Jan 2020 11:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865427; bh=FqMITQzpPmnKmgUK//ibo6+YIPZyhuZ0wjCpj8u/7n4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eNGGTimWp3cn12NBK9kKBuOMex8YQNp/OHrf7oIMC3v26+p5ORnklCzPC+x2arDre H+0VtxWwc3VGK2Nx6rZb2cfyqwfk92IERAAHsOy0LCDyPafBraT87UOM3yS2PC+SUQ qTnszGg36JeVcmvVXhHwbz/W4UnpRSiQRPfoy/8g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tri Vo , Kalesh Singh , Ravi Chandra Sadineni , Viresh Kumar , Stephen Boyd , "Rafael J. Wysocki" , Sebastian Reichel , Sasha Levin Subject: [PATCH 4.19 530/639] power: supply: Init device wakeup after device_add() Date: Fri, 24 Jan 2020 10:31:40 +0100 Message-Id: <20200124093155.218055161@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Stephen Boyd [ Upstream commit 8288022284859acbcc3cf1a073a1e2692d6c2543 ] We may want to use the device pointer in device_init_wakeup() with functions that expect the device to already be added with device_add(). For example, if we were to link the device initializing wakeup to something in sysfs such as a class for wakeups we'll run into an error. It looks like this code was written with the assumption that the device would be added before initializing wakeup due to the order of operations in power_supply_unregister(). Let's change the order of operations so we don't run into problems here. Fixes: 948dcf966228 ("power_supply: Prevent suspend until power supply events are processed") Cc: Greg Kroah-Hartman Cc: Tri Vo Cc: Kalesh Singh Cc: Ravi Chandra Sadineni Cc: Viresh Kumar Signed-off-by: Stephen Boyd Acked-by: Rafael J. Wysocki Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/power_supply_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index e85361878450c..e43a7b3b570c4 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -902,14 +902,14 @@ __power_supply_register(struct device *parent, } spin_lock_init(&psy->changed_lock); - rc = device_init_wakeup(dev, ws); - if (rc) - goto wakeup_init_failed; - rc = device_add(dev); if (rc) goto device_add_failed; + rc = device_init_wakeup(dev, ws); + if (rc) + goto wakeup_init_failed; + rc = psy_register_thermal(psy); if (rc) goto register_thermal_failed; @@ -946,8 +946,8 @@ register_cooler_failed: psy_unregister_thermal(psy); register_thermal_failed: device_del(dev); -device_add_failed: wakeup_init_failed: +device_add_failed: check_supplies_failed: dev_set_name_failed: put_device(dev);