From patchwork Mon Jul 19 14:52:36 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: 479929 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4240122jao; Mon, 19 Jul 2021 08:37:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcnVmWOQUcclsisn0ZcR6p6lWZI0GPjEZX+9iKTVLPf7WqhQWRmGSUBbHFsO0cRTIIKUBT X-Received: by 2002:a5e:8e02:: with SMTP id a2mr4115715ion.205.1626708740081; Mon, 19 Jul 2021 08:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708740; cv=none; d=google.com; s=arc-20160816; b=mp2fkq4R13boSyyiB3uRbIXHV7zQ1Kq3qzXZHdEhIBRyY5WFmfDtGLu/ccRh/RicRM G8Xhhuge83QrwYuQAmydwphoNWHrpBLCJCj6pWSV+HghekkwTRudHLbnJGg55ZW+NnWl sxkypgbhNvtjAOQae8CnEGMKxfyvTE069YSevgBgVW5qxHGR8YH0fV4C1aeGHPgLPgTK hdPV10wM109lxQNNctIpJk76yTAeAsRKp4BfBJFGJKAsyeyQ1ahugKNx5uP3IGKyET3Z FBTyaepe1ZYPSKqujTrG+RXZUvXTwWl8l2ICYeDc0kgeoiaaWsXLNbRYCby5P9nt1F/e 4TrQ== 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=NFv6mGIuEFSLsoldBepPZ/aqZBxoFbQFdQTn2DVNJRo=; b=VJKUV4Ym2YurPywSK3DJARz6ubabUr+YZBdOA6U4tHjY8Gwm3JSLIalDNBF5CUosw8 pFDR3uycGoPHn47Z/dmCxdAsFk8sN4+hwaty2BLBpxQOlhHxCD7qW+WkkgwVlgrVlUy7 AAC7BQg4p1qnXoVSdv35rWc558+Vq92XRPfVXLPS9RXIOSYIVqiVIh3o4/GtVAgKP9Yi qSJMQWDx23D2ir/xXy1m7xMo6lhqvs+jxRYFbn6y0PH4GuRGnl4tvOnAvb1uXnf9h876 Ix9AqEmKBDWSbIO+PPWmziX7r0ZaQfpvrcMnd4U/szgF3ypkXDSAPn13MVRPrXlKcKmQ 7hCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CmzjmZTP; 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 g5si10245056ilk.74.2021.07.19.08.32.19; Mon, 19 Jul 2021 08:32: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=CmzjmZTP; 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 S241018AbhGSOvJ (ORCPT + 12 others); Mon, 19 Jul 2021 10:51:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:40446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343891AbhGSOsf (ORCPT ); Mon, 19 Jul 2021 10:48:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CC7061263; Mon, 19 Jul 2021 15:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626708322; bh=RHz1293Or9glW9h0I1wJ0BaHJz6pfTXd6PQSHZjnH6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CmzjmZTPjdwqgz6dXhwlgcow/5q8f/v+SQcufMQpLnK8rcT8s8I1RidsewlIgQUEh vfGTvRhn6haLNrElrcaLPVPv14Q/vsoSCC2/Bqiv2HP9cdSPynTbuOEricZpFIIHjB EdarMzrwwoa6d/GtzDtKACU+dSciERNkZArorTIQ= 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.14 267/315] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:52:36 +0200 Message-Id: <20210719144952.196381447@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@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 5a76c6d343de..8e74d27fad29 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);