Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp971224rdb; Wed, 24 Jan 2024 00:12:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLlBGp9vHr8BX730SdSm67KZXEr54VOgDlrqu9qCE7zFKTnoQF7pdQD0JbQiAF2gWPy2rA X-Received: by 2002:a17:902:d490:b0:1d7:1ef4:1512 with SMTP id c16-20020a170902d49000b001d71ef41512mr735022plg.20.1706083935188; Wed, 24 Jan 2024 00:12:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706083935; cv=pass; d=google.com; s=arc-20160816; b=Mn4ER1sxg7yfgKOjoD0Grd4WohFP0zToC1AGzZb4e6H2KkYdlRgI4+EfmhBjBv6gB4 TtCXsPUp9nURmktFxTK1tpMIMn9f1XbNOu9lOhs9EKiwqXHVRXt3JIAAlvGtdpBfYSzp oe6AmJ8JwfksA+0Dh+oHGdlwa/668oJ0Vtd43GK91KaaadLuQ3a9U0QmwXa2CQDR9nIv yazwhGZAZHxC97jfsqf44TMm42j0yoJp/XDABo5YT2/Hmn8swWCg+f1o0KTDAFlDPYhL QtHA8v5TYHzd2YJ9WmhZs2KDJqQ6SbVhHMvXsiYBI1gexFBb8OS2qsipEGjWwSrXBcNT qxEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SkOmPMRVcjStvW0qoYsB2w+BdRQCPE3pgyuKcUlf9HM=; fh=8D65eNEHIK7HkcfIZH0MJnh1/7r86pgAZRCnUcYHDdQ=; b=Pwf8woNK76eWjguV0xGrCkdBSUdNaVafBuhNs/+dayYo6DpZb8BqK9KglVoEiEkZTS 4PGqCcRhz2KpIkHK4P9SfdAFG5abP8EiAHdcHJ+c2cY8Hk1gaoAnLX3A+iCiPBfK92FF FV2qrwnVOawPYxf64WSQXgs+/dJPR94kTTupq9ee37gEnVtQdBsZD+rFkuVphHuhIWyl 0zyBmRi2JgVdAKmo+7UVwU7vkyB+9VH8B5wYcLs63FMB2078rON53nUfSp91lMUY6Grm FKEjPqN8tN3+Pii8XeQte+3T3wu/JMctJ4nshOn7FPtrg32oXeAGCy7rXlL8qq4gIC+s sEIQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TkRH08Og; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-36597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36597-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n10-20020a170902d2ca00b001d4dff2c4desi7998427plc.24.2024.01.24.00.12.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 00:12:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TkRH08Og; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-36597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36597-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 56F0D292D4B for ; Wed, 24 Jan 2024 07:55:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A573171DC; Wed, 24 Jan 2024 07:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TkRH08Og" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D927171A2; Wed, 24 Jan 2024 07:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706082923; cv=none; b=EXilB8yHl7KqeNxS2xW2p+8eLurKp0DVSN7itScrju/KdSqsWZnm3wPUIbkvBi9YoBKviH3L9zfv3oc2fD34SxMSls1Rz7jPGh/uA6NF9h8QwC+XPdBDfswR4dIsfkD/mzsWhlnXi/t3Zh7RG+GJx+627CmRam6IJj+i9tIciOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706082923; c=relaxed/simple; bh=NT+Vf9nE136+iQ8X8hrDDr0oPQKV4IFmb3UOTg7wN3o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bX9FBKRahkIrbS5a2cZf/IHVuOS//wBC4sj0D16jIMK2vN6mBxQCOvZCvs1rcKwtvGmxFMsBNrMo8wycKtPimeq1FkmITjzJoYwKIpGvJJ2UA4JzEL9ZH5Rh+pzSK8iCdGON16yxNx58BWVYHqV3aZE45R2xJW4z9BU2vdDgAX8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TkRH08Og; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C1E6C433F1; Wed, 24 Jan 2024 07:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706082923; bh=NT+Vf9nE136+iQ8X8hrDDr0oPQKV4IFmb3UOTg7wN3o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TkRH08OgLfYznR6++IxYRcC8cWcUxVT2AGh+/llDdDJrT9H2O65CLo0sndqoqhrid JUU8ui2mXII78nEmwj4AegguQmGfCbuiVVONq0PXfrVe3Zg9wylzj6D1kCovi7KINd iJNZf0CTtBYymdHlfZn6r8g0DsufA4wb2FzSVfjcF7AOFm7xlvBXMWDdCk4BYE1uUA +kOor9A6L874Ndg2jhIB2K8nhpq0xo9mVZq8RfWOIK1JysnQWcsfgPjqTgeXpD0hVG HRnCOYHlJeDcwGm+NG+I0mNT1LeJZVxfAYeRh0NiiRbtcEZeM/pKR5PyTXAf4C7pQH RRGqU28b9c+Eg== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1rSY6h-000000001VA-1JkT; Wed, 24 Jan 2024 08:55:35 +0100 Date: Wed, 24 Jan 2024 08:55:35 +0100 From: Johan Hovold To: Konrad Dybcio Cc: Bjorn Andersson , Sebastian Reichel , Marijn Suijten , Sebastian Reichel , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Xilin Wu Subject: Re: [PATCH v2] power: supply: qcom_battmgr: Ignore notifications before initialization Message-ID: References: <20240103-topic-battmgr2-v2-1-c07b9206a2a5@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jan 23, 2024 at 06:53:46PM +0100, Konrad Dybcio wrote: > On 1/23/24 16:59, Johan Hovold wrote: > > On Wed, Jan 03, 2024 at 01:36:08PM +0100, Konrad Dybcio wrote: > >> Commit b43f7ddc2b7a ("power: supply: qcom_battmgr: Register the power > >> supplies after PDR is up") moved the devm_power_supply_register() calls > >> so that the power supply devices are not registered before we go through > >> the entire initialization sequence (power up the ADSP remote processor, > >> wait for it to come online, coordinate with userspace..). > >> > >> Some firmware versions (e.g. on SM8550) seem to leave battmgr at least > >> partly initialized when exiting the bootloader and loading Linux. Check > >> if the power supply devices are registered before consuming the battmgr > >> notifications. > >> + if (!battmgr->bat_psy) > >> + return; > > > > This is not a proper fix. You register 3-4 class devices and only check > > one. Even if your checked the last one, there's no locking or barriers > > in place to prevent this from breaking. > > > > Deferred registration of the class devices also risks missing > > notifications as you'll be spending time on registration after the > > service has gone live. > > > > I'm sure all of this can be handled but as it is non-trivial and the > > motivation for the offending commit is questionable to begin with, I > > suggest reverting for now. > > > > I'll send a revert for Sebastian to consider. > > What you're saying is valid, but a "battery" device is always expected > to be present. Yes, but that's not the point. battmgr->bat_psy is the first class device pointer to be initialised, but that being set does not mean that the other pointers are not still NULL when you hit this callback. > If devm_power_supply_register fails, things would go very > south very fast anyway. Eh, no. Before the offending commit, if registration fails, we bail out from probe() before registering the PMIC GLINK client (and callbacks) so all is good. That is no longer the case since b43f7ddc2b7a ("power: supply: qcom_battmgr: Register the power supplies after PDR is up") which happily ignores errors and could theoretically result in all but the first class device being registered leading to further NULL derefs on notifications. I could have pointed this out in the commit message for the revert. > I personally don't see this being a terribly bad fix, but I'm open to > different propositions. It's not a correct fix, only a band-aid that papers over the immediate issue, I'm afraid. Let's revert and if you care deeply about this you can possibly propose a complete patch that addresses the above issues, even if I'm more inclined to leave things as they were and not spend more time on this. Johan