From patchwork Mon Jul 19 14:53:18 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: 480028 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4285453jao; Mon, 19 Jul 2021 09:28:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvxXoUD1lSw4ZEWYgTeOxiseGUs/Hf4G2hN9q/d6vD+L5lDDXeHHlQrCT5hQTDNMMr4nMG X-Received: by 2002:a05:6402:29a:: with SMTP id l26mr35470924edv.207.1626712110969; Mon, 19 Jul 2021 09:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626712110; cv=none; d=google.com; s=arc-20160816; b=J6x3HAcrUU3qHDDM5dvWRVmRVLIxROj5ffWOUyKCGN9WWgaF22xyDREVda3Z+n60be BE+8BdZ004xnjTKSQYX2Wx9170+wuFSYjW1POeHdLg7QnR4wMOzBaJjGes4z6M+4T5Ei N67znj+EGHAeyNSuN5XsoAVcgGVE3NMVOpF5uNrdnKdJ19KZ5VtSZzovdfeE1NcxjaHt aqOk3IiCVWt9Zs/CoXV/G+tbA67lLbJey75HfQD+6kdv6mqr+s6MhTzadvUoxzoyPzI7 pCgg4b8iQasN5/s21kP66gM1IgbGu30SEF35J1FDvVBKW58yqzhK2C4a4tmoV73kvuZ+ hZGg== 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=qdD0B0JQBhFsObk6PIR4DBJjqj2UsWrTBnbFmQBORvc=; b=ryzlq1oTAf6Tx1VNvCXMBdN3wI91D9WQnYHZLgzdjnui0zAqGVVLXSzjserZlJ0Vu/ g3LED5zgWizFLYG3KTaAdaFqTz3/ADZkSDPS28I6+T7Rr9j0+WTVYwKN94IyQi/Il+hJ Ggs/joKIuKiBiClP6JtOW/FOF/23FGXOBEtDlHRfz6qQ6bzmtX1/jduS5zXUUYnDREmP x69n96+LeqmwLU08KiLNzNwxeq4thrpZqREyqOhGewiK82yeGMV1SdqMpDZK46Th8DqI fDEsk+Hbr/PJ/W6Dhd8rM/B8zkG8OXXG1lyxCfELwGQJcdHEYQpTvp5y2LSRvCU1Uxt3 fjhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k1Pg/QvC"; 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.28.30; Mon, 19 Jul 2021 09:28:30 -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="k1Pg/QvC"; 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 S1343785AbhGSPq3 (ORCPT + 12 others); Mon, 19 Jul 2021 11:46:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:44952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348905AbhGSPoe (ORCPT ); Mon, 19 Jul 2021 11:44:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2158F6147E; Mon, 19 Jul 2021 16:23:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626711798; bh=R1dpeNmez9kyz+gPVJGnZ0wHDc64/TzsvL3fYSbC0nY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1Pg/QvCzhdNpdOQ5pibk5aqZ8ZT8bdaVcm4PRlsc5UjsXtTQTLkxEjI06cYleu3L ioq7+3B0+4uCdNbIkafra1hnpDQclZNWe45AtZMP2hh1p28S7yPVRww6MSH8K1go/j U69GfYzJosGSOOYhyEUDNvgB3obhPbNaqZwvQH4k= 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.12 136/292] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:53:18 +0200 Message-Id: <20210719144946.956138103@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.514164272@linuxfoundation.org> References: <20210719144942.514164272@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 ac77c8882d17..893185448284 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);