From patchwork Mon Jul 19 14:52:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 479991 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4268095jao; Mon, 19 Jul 2021 09:08:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNUykrBWOdJZCfaReZOh/XZUsOlL7u4yud1McIp9jFqtkr5/jCGCP1z41u7J0GHbeM/ZDa X-Received: by 2002:a05:6402:30ba:: with SMTP id df26mr35439977edb.310.1626710916838; Mon, 19 Jul 2021 09:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626710916; cv=none; d=google.com; s=arc-20160816; b=JOT/ojmmpZjh54FdA/da9Y6nIE3an7fOMNr+0d6CMYyIa1/M/cPH3Gecfu3a/xLUdm tgYdjB0ES0vS7+PIALsSXzKpFRv/kjOT8C1DFPiq4WIM5TbqlzHDN7TXUZ6emTnHUTW+ gYLdT9Yw4a7azwud02yw545dYwh0QTV3gD1itCMXq/M88/kE3wx6OWJ2ldmCtcJFn8/U wDTvQJTMlmBxgzezhlcShg/wBV3nuXJEcBuoJa0bHh/GqdvaVgKSybeDvBzpHBomX4Zj wOZkIDmzgb3/Zfa/TVTBX+Zf1WaBz4LduKXmIGepD7Pf6SZTtcP5l7kwyZS2Q08PBKYL rgOA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DKqwAzKgosfNR4xl/zWK+wXukgl48hKcgS/dgAEnhTs=; b=xLfmPnCHsSCgG+4rwcEu05gRrZf0mZomUgRNaOGPS2vOnqWr3YxOztPpfKDFHAOxYx j/VfFTzjfRGyFNWf1qfsGDDx2nduh9pKoGsrp1Qv8laUr+oezOl1WITFuYh4sm/TEbiM BgsgTRFXjztihHHquXqyRgEym6cT6/4QLl0q1Fcb4UnLtfq+zFVzD7FbOjSCqL+3cKxY ivSy0FI7W1oMr5Ywv4SW0npGu5kk0if6dhNrLLWzXcXP+tdK4bj9R0lC70vNq+9wwb+S Dupy24IU2n6HjIFOqbq9DSnmR3HFUO2fABnoGP2G2a8WySvTe7tMlhcyrBaW55XcTeFx zyWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D+pkC8OD; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id la14si22045543ejc.142.2021.07.19.09.08.36; Mon, 19 Jul 2021 09:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D+pkC8OD; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349177AbhGSPZs (ORCPT + 12 others); Mon, 19 Jul 2021 11:25:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:58060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346663AbhGSPRs (ORCPT ); Mon, 19 Jul 2021 11:17:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E4FD61285; Mon, 19 Jul 2021 15:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710272; bh=UeCvVDPoh1OLSrZIlpm701XxGHZ0KFMRQimJk6/CQhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D+pkC8ODCdUMTEltCr+/lwerMxLusdt1GYzXwGEDRwqh43hK5H7bRebdLgincANjQ 0YFK4vKoL13rOIZvMvniYg3uoUzzENCc/eQ3802DPWtMbjpvX8UaoKJ3Fpc4mFFZo8 JbMZ2Gpf9ftycYJcCs0NNIO/bYXF2r4FmZA7n7jY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Walleij , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.10 115/243] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:52:24 +0200 Message-Id: <20210719144944.620412444@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Linus Walleij [ Upstream commit 5bcb5087c9dd3dca1ff0ebd8002c5313c9332b56 ] Sometimes the code will crash because we haven't enabled AC or USB charging and thus not created the corresponding psy device. Fix it by checking that it is there before notifying. Signed-off-by: Linus Walleij Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/ab8500_charger.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index db65be026920..6765d0901320 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -413,6 +413,14 @@ disable_otp: static void ab8500_power_supply_changed(struct ab8500_charger *di, struct power_supply *psy) { + /* + * This happens if we get notifications or interrupts and + * the platform has been configured not to support one or + * other type of charging. + */ + if (!psy) + return; + if (di->autopower_cfg) { if (!di->usb.charger_connected && !di->ac.charger_connected && @@ -439,7 +447,15 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di, if (!connected) di->flags.vbus_drop_end = false; - sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, "present"); + /* + * Sometimes the platform is configured not to support + * USB charging and no psy has been created, but we still + * will get these notifications. + */ + if (di->usb_chg.psy) { + sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, + "present"); + } if (connected) { mutex_lock(&di->charger_attached_mutex);