From patchwork Mon Jul 19 14:52:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 479857 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4211663jao; Mon, 19 Jul 2021 08:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymzIIuNu0hTVUu+iTooI0yy8QJ5HGTI2df0Gl5cSDYPWGdkus2vNF9pva7pN/LjJl72NeO X-Received: by 2002:a92:8e45:: with SMTP id k5mr18038821ilh.116.1626707163809; Mon, 19 Jul 2021 08:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707163; cv=none; d=google.com; s=arc-20160816; b=RNDv0VR8v3dO8/nd6CT/m7EIrIyaMpRSHr6AD80ZXm1TK/XpgE/VbdzFEmhpfKKpzG yKjT60qbzaK9q/jj4hKdwxj6aYweTvktI5hUH5FupnADNvo9xXUMZS8MQ2rkCiLZdDlj FFaVE3hClnlJyCMEZ5vS9ywn5s5Ia4758I1hwjuV0Oi+jRX5WVIKLo2LzLM0qrOGU02X vlTTrE6gXvTc0OjKajFKFj7u0GD2Be/Ct90PE+ZjYBVqsCoivEBOZvJjQU1tamxp6iqm iI7dE6qFzpoYwlMCZxXNFEhTse2sWkwnZ6F4mUH6gzyShDYarusA/29Lzg/BiRFd95in 5ndA== 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=DGAbVLFLfaGw6CSShojsNPBfBwsqgCeYWg94Rza9bGM=; b=fbjstKSRDFBrqbrAdtDyhGOA352BREai6rA22cTiapi0NRCGGBL92/hWPgpdxPqDJh dHTTQSJBLpuQlpBf5G4j4fT6K3uVe1EIQReIZRMdK+scQFWpVyJ9NtG7Rd6QqLprWcA5 f/2m6r41/+1/qBd5aWLek0zclzgv+cLje836vIzlYBJL221VXY6xQlQpXg8KXUkZ/0Ns UZBTC/QmSTOzlIwRyglyjMSSc3fXu1Nd9i0X7nRYTwKtJgqQEbAtMPTK/nkUiMx8dJcm mqoxq75PBNwweAsMuuhyUDDVjCkVXZ5IWVjb/7t3J4awKUtSByOwNjNE3Vo0AnEiagx/ j5rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n7FlFHao; 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 i9si21653919ioq.17.2021.07.19.08.06.03; Mon, 19 Jul 2021 08:06:03 -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=n7FlFHao; 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 S242607AbhGSOZU (ORCPT + 12 others); Mon, 19 Jul 2021 10:25:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:55982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243144AbhGSOW0 (ORCPT ); Mon, 19 Jul 2021 10:22:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0AC7061245; Mon, 19 Jul 2021 15:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626706955; bh=Sh3k0haP4j3m4OI1KzmGOpnxvyieK4bU3KKRJYtp9Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n7FlFHaoXEY2OT4OxJXvOrB2rYWPIg02lJR9oOMDwqxv0A3lEH7wbKeP1Sd6EPT81 kzaL1kz0O7UKcpZ7z/Iy49mToSizx1k2L1TPwT/ujTNMTOkDednANAAL13hj2bSgpM juI55+yw3hLsnUIS7WOteo3rMF97yWY7z7Sx/3o0= 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.4 165/188] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:52:29 +0200 Message-Id: <20210719144941.894489969@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144913.076563739@linuxfoundation.org> References: <20210719144913.076563739@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/ab8500_charger.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c index e388171f4e58..98724c3a28e5 100644 --- a/drivers/power/ab8500_charger.c +++ b/drivers/power/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);