From patchwork Mon Jul 19 14:53:00 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: 479979 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4254085jao; Mon, 19 Jul 2021 08:52:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvr2nVdDtl9MR53wmZn/sN+qxcjIQZr3a4o5y613WwhreBdHbtS8cyIUskHlJFtRiyC0H6 X-Received: by 2002:a05:6402:3454:: with SMTP id l20mr34962616edc.170.1626709960773; Mon, 19 Jul 2021 08:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626709960; cv=none; d=google.com; s=arc-20160816; b=ypy6jWv64LxV5JwykjVNL9eGghnh7gHn6I6ihtI0Nxdu+0gq2zmmswujAW3smh1cKe 0exbgP4b91F5GU2n6eCYhUHY2Zw65Af/mH1EXF5Qdtnv6Ov/rE/aJ515bDi4ujiwIeg7 6gsA6fXkFZLH1Di9McUdG7mot+zXIpunsFUCuyZO4Nr11ZnFrsCAwuRQ5dYbnLoHFDVR 00ecN2PiwEELyrp6ilkrRA+JtnJao1S1rcrSwIfFHpIIzSQQhHGS5ClVayjoz6pZs0n3 y6wO3Kvmd+jJWeO8P9eDyKQTZQyH+0tqdlVugIqY4rQHEz1wqZxTv+8M/Pa6sUx0n9+I 6jdA== 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=URaPvQGl1IQKrSp8J5AyzS8YHPKgLHcX3q2KxTr8+AQ=; b=MG6VKAwmySMao677lTwdho8770BITWFz+uFh7sfIuyWT6L/ymph/+ccNn9iknVC4MO D29pHCXR+k7mtSO1FJ+Lsx1zgwBaU0NGlhoUCKOqNz+iicH380UworbKNk+xfZTc8Ie2 3rix2BmL4sDEFn7Hx8VdVPSvQ2aMWVL99wCqh1JE1hOvSthEts/CiKAlDwh4+ayagcq5 MX6u45vRABcTWTMO2SM63wOC0kIPuI7ixk7I6cfLKoPpKXMDaF678r6qUKxjY6NYk5xE QPqyb1NalClkJvqBMRFacbjCpNoNp6abadVtjXZK3RYt8WDdNndXKzlj+Sit4iSFy9Be A9gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CeBdp5yr; 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 h13si9820360ejs.401.2021.07.19.08.52.40; Mon, 19 Jul 2021 08:52:40 -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=CeBdp5yr; 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 S1345515AbhGSPLl (ORCPT + 12 others); Mon, 19 Jul 2021 11:11:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:40612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344771AbhGSPJJ (ORCPT ); Mon, 19 Jul 2021 11:09:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D192561363; Mon, 19 Jul 2021 15:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626709722; bh=Qd4pgqR1OCa6+4dBwCo8x/QTkWz6rgYkwjTbcm0aT6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CeBdp5yrV0RLtMUgGZV5LYB1/LvI+W1aMB43fNAf5w7cc6M6lPBMQhkK1C2//3MrF TdBhH7Nalw+eCHI97NOR9c3qzcsQShZY4wvTL8FybMa6KQzq3cIr2kTSxFtKeNb/VF TzWTWlYNA+Rz+2tWSaFdxM3UxZra0VZHEOQm72rU= 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.4 072/149] power: supply: ab8500: Avoid NULL pointers Date: Mon, 19 Jul 2021 16:53:00 +0200 Message-Id: <20210719144918.361678422@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144901.370365147@linuxfoundation.org> References: <20210719144901.370365147@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 e51d0e72beea..90dbf3760e83 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -407,6 +407,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 && @@ -433,7 +441,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);