From patchwork Mon Jul 19 14:51:39 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: 480006 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4276682jao; Mon, 19 Jul 2021 09:17:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOfH1KxYbZ8G0zhKUSXmO3kIdd2Yp8FxaArGLqs9YD9b2wRTsIxQwio6LbWmngQ3qgCrrE X-Received: by 2002:a17:907:9719:: with SMTP id jg25mr20656022ejc.362.1626711469761; Mon, 19 Jul 2021 09:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626711469; cv=none; d=google.com; s=arc-20160816; b=i/2W6usFS8birIhTVfXmfynswU+CxAw7iU+9tgEsUHYBTGvXzoNbZRXWNO12NtMrAv ct5r1o/5xQGCsFgUKVAOluanufk/5rAyR5om8wpvTAtAw4AFehfXV9aNXLuht/MsrI70 qu1eBBjwaV2GMKuP954gYcazZrLzdT5renA3AnSUZmqXrZlxGxHQ71OKHmcayJbt1u8p BhSu1Jx4qHQGkc6FmJnEGaXif1+voS5/7peZOKS4nFNGxWV4ezXxvy2vVy5NgrzXuL2r hj75aYC/jXS38QIoHhqdaHVArLISxD/CBg7u0MSka5BXi1QjZnOMbtzzKZko0gILzCwN /NJA== 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=2OG4xm/EByD3hc47QAMQ7ANQgj57bH6XadMN3gW0uJ4=; b=q5k1k3hXIlYfVO7BAFKTWvkBdXtJJEr6w+1Chji06mxEmuFLQ5OEhrFfoh2RmJYW6G +e1eyFIFwN4t3VfrsYnX2u4cuH/b27O1EW72sd/J2Gv/eeskmZVbOBfQfY7b+zGq+WEk FotlT0f1ba9pGRoRZOeJBGCPmC+Qzls7ZBQVqJfG3gQL5Lzx/dTGrOSREdn9twVRmY5s V5Ji4A0jllXm9eVAazAXlk0nxr+ylY67QRKs2/e4jHlP4aeTQIqo5nc5I2xGtWZMCfMK cPBOezNvoBZFV8P1aZEr4ZWR3vQMPOFmA9Itqyi3H8AytBohIn9UbLjwTRNtdUOn41PU 0qkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gsTSnXrh; 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.17.49; Mon, 19 Jul 2021 09:17:49 -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=gsTSnXrh; 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 S238554AbhGSPcx (ORCPT + 12 others); Mon, 19 Jul 2021 11:32:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:48624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346705AbhGSP2M (ORCPT ); Mon, 19 Jul 2021 11:28:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1D49E6128E; Mon, 19 Jul 2021 16:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710906; bh=v6UqtFtjG4iruUiQJF78ThgQFAMWAej5WqbCRUipamI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gsTSnXrhx1HvGuh52WbJlah/Foe2kLcDv+LiCHUnRTZK7kdOVHffVYMKyWL5tI+XI ZWwbKpqfAWyeaDlZQeHJhFX868YTAbxopecaJX01x2dc2fS87jnYrAgY65R/0DRLEc yLAFmpC8lyf3B1krRpMXtAdRQVymp7Zil7nNp5Q8= 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.13 153/351] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:51:39 +0200 Message-Id: <20210719144950.038235048@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144944.537151528@linuxfoundation.org> References: <20210719144944.537151528@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 af32cfae9f19..57fbfe3d8c03 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -415,6 +415,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 && @@ -441,7 +449,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);