From patchwork Mon Jul 19 14:52:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 479886 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4221180jao; Mon, 19 Jul 2021 08:16:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy++d2bmxCh9ApPaOD3szh4/3325f97otYf4hwOSKo9HSGnrwLYZS/lnX6msY++Jx3oAFlw X-Received: by 2002:a05:6638:c58:: with SMTP id g24mr22069874jal.63.1626707780219; Mon, 19 Jul 2021 08:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707780; cv=none; d=google.com; s=arc-20160816; b=GMT6bzyX12FiBp+IHelF5vevy8GH8Y1iayIDfgTipFmhkLvdwP4KPbzsElpv+YdiQz 7fWrwY8tBRQf4yImPfRUbwBJckwrJqgmjI/FYkVHutZGtYyQJKIDfsTbqYqOWKX9+XrE 8Aot89avs2cOeqxu/HW+4A2FjwtCPvjMeY6APiKfvAgoiuRor6xwVrVSRWEqsHGWeGHN 3q4nNlMqOostSBC3G93AThrAJPiH4BaPIzmDXXDb9X/uyEzHdijOnL2PEbLIaWFuUFKb tjoerErKv4kWKmbFu6iGGryH1o4Q60h/69U1Z7OOu7SeVakmJQvuhq+ojwKZze8U6peg DvPQ== 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=RPVm2ufViuCMBwEm3mzrHCvvO9RR95+kK18h+AmWeHo=; b=mEHJy8QeyN/RVdSmdUUWS4dCCWcK9lVUlmSXIcltceXj/mwF2FV4jZgcUS7IGEYkfC S5zE0/Z69Kj01MGN30PyqA9ComRimZBkKHAs0YjK1Sh7We4gxr7uUhfJKX25OA2gr1rJ dl0aB7RUH+kgQ3SRQiVPDonuPk2O9IuRLdFJ9+5s76WGns6QozGFG715IUynybIXcpV8 Dn+kOLE1BaEb4+7uHWB4o3XUC163pprve/azi/Dl2NsU0v1Y0B/CnZjQrXEArOyLv62F /HsJtW346v9ZhAh5unfejEEJnRaCii7IRVk5AVXMJTc3vRFFMzK1QxZLjoXMcKg+kUdq VoSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qZmBXw/M"; 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 t25si10528964ios.38.2021.07.19.08.16.19; Mon, 19 Jul 2021 08:16:20 -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="qZmBXw/M"; 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 S242819AbhGSOfg (ORCPT + 12 others); Mon, 19 Jul 2021 10:35:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:47206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245577AbhGSOeq (ORCPT ); Mon, 19 Jul 2021 10:34:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3809F6135B; Mon, 19 Jul 2021 15:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707660; bh=zW/+9TjAzUHJpOauq3MOoubO2rCelNtNxt/izos+Htw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qZmBXw/MJT/3JWWLH5ENmTaVF/QkNPlbNibxX8wqlHd4Xn6fY3j2ThoL6I7Qb1zCn 4MFqPy3Yppf5YQUSB5j8FLo3tnK/Mpxdqoy0dlVAs96vtSjKOCgg51qxzlv/wXmcDa wNWkAiBqpx56+OSi/6sZhIkbqu1JX756Jf98FFhw= 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 4.9 209/245] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:52:31 +0200 Message-Id: <20210719144947.159739095@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@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 48a11fd86a7f..2d44a68b62c0 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -409,6 +409,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 && @@ -435,7 +443,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);