Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3854154pxv; Mon, 19 Jul 2021 10:18:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR/ZFEhznyWwq6AVtM1aLMzb2VlioT5TD4QoCzJAuzQKm88qQBfgTVEbCDSn2PvjlZdF+2 X-Received: by 2002:aa7:c04e:: with SMTP id k14mr35089846edo.157.1626715117861; Mon, 19 Jul 2021 10:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715117; cv=none; d=google.com; s=arc-20160816; b=mAta09YOkK2S73AZh1Ph9nct6INnAH7JZDOn+xnxB+qqBSpk2ieOqHvBjPVywHOiSW woLE64qGXvx13ZTJ3+zrGbxEgw4iNZ3lt7EKQJOGrrenqfTrQJTJ6vzq46c+0rg1GbO8 Jd3vZVJReul1RRcw3RVQcyveMVGmLm+HSj7+ggItCj7xQRv2LQMIEl6kM2E3YUNXOxCV gG0t9qIcJOjpxA/EzEyf7tGM1kxDWCdwKUcdo5eh10viXYlO2UeFFkp2aLUPpYPJv294 2URiJXzLS0ifzVWcfcvsFJ8ANN6FHaBthl3ThDzVUO922pVeyrr7m0a4C5arh4BC9XL/ Qa3w== 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=OCb0UR1xuHTIxZuT5NayTYqCzn78JWWTwpi9Dao2KobxAN34iTGiK1/o0jeqd32ND2 2E5UvPrsWGV9KLZVLfj5ah0fSt8DXq7cQfaILRbIEsZkkErWV+X7iW0c3UrSlGcM/r8d MnKvH3wdgvdq6p7K9Rm9md6zz+hzVNYamIpo2ly2P8+UylivQPyGcTAi0dKpE0wAZtxD ZP+D8R++LR8B7kp2FGBM6o7kMIAVOS6V5CNcq6/VXPJXH7iARnRwyM8AxEab//28bxxW QbvXzilXHZyA/ougmdEhbU7wxhpGtbJ1prvyCcWKku9MXemBtNxcG/vL6eVjWPU4NQBf qlcA== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 gf2si26577725ejb.500.2021.07.19.10.18.15; Mon, 19 Jul 2021 10:18:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1350634AbhGSQeK (ORCPT + 99 others); Mon, 19 Jul 2021 12:34:10 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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); -- 2.30.2