From patchwork Sat Jan 23 22:19:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 369464 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp2688136jam; Sat, 23 Jan 2021 14:21:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxX9TI1/dBSuksLLTdf/RPBtml5FNWczKf2qdCIU4zykW8EyMgs1x9uPcpFkhxGEc2X9DBq X-Received: by 2002:a17:906:9941:: with SMTP id zm1mr103273ejb.522.1611440518417; Sat, 23 Jan 2021 14:21:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611440518; cv=none; d=google.com; s=arc-20160816; b=D2CuKUqUXF1RibfDTBTlr/WtMDcOxH60X5j8CckNHuIfWXJMXeOoBhdQDTWsGbjyj3 Yel6EMKTL+ylIpMdld9cEKZlxIZuVRLTFbo+PVsXRrNIyLf90alOX6T04jrEn05WbvKp 7LmxCYcgpS6+Nd79T90bttQDUDUKxPne1nmKTy5elvjvyfzu5hINahIjnCeU6BV/zDuM xwrmegPsitJjeWPjGWM0/Xj6Rzk9I6KrTd7qoTScNRjqPCf9B5PrT9EhsTJALi8SdXAS KF3DzVMA4RlYBFxcLifn2YpY20Q+3QL8nRG/v1UBKAn+WMLx6GkUfvgdh2gxkhYmWKcQ PlkQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/CksNMLgJxQqZTGvVoyYFDLCuLf1sggTOdB/wwyAbMc=; b=UOFVuH5hpCGxPl+0jyglaAMnhKZMNckRu5zt2uQuk8oDKNY3DohNzikUXk9d/5DydT AT8FB8CZmPb25I+kwEU0fjim5hlJY3+UwPqxTOZAWUa9bcXVACNxZwITWkvPSm3SCbhT Rsp0rQuErXh0oEgc9kfSBVQXoJhcV/aBPcTEsLTOCTwvlnkzB6dGr7a1AXKEz/8irQdu xnQPLLxuTgZhj0I1N6jPATSMzfKdAQ4QfhwuUD1hnwvnwccUKavCSooHpahDoDVTiGs5 pCg4QQR9cJAmVJ0cVafE0urOS0vS5GCJi7PjR2aFeaZ4buHTw1hcW07HMhMmY6ENL/NK 0joA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g+doe8cn; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gw11si4392384ejb.414.2021.01.23.14.21.58; Sat, 23 Jan 2021 14:21:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-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=@linaro.org header.s=google header.b=g+doe8cn; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725932AbhAWWUl (ORCPT + 7 others); Sat, 23 Jan 2021 17:20:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbhAWWUk (ORCPT ); Sat, 23 Jan 2021 17:20:40 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C174EC0617A7 for ; Sat, 23 Jan 2021 14:19:29 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id a8so12572281lfi.8 for ; Sat, 23 Jan 2021 14:19:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/CksNMLgJxQqZTGvVoyYFDLCuLf1sggTOdB/wwyAbMc=; b=g+doe8cnX4AH/zqBgFiZLGkj/6fvpGOj5vh8JVDHl4lCTEjJG8acnX+rgAzu3V50YH I9wGtscjnSn9xzfyLbLi1OxMCJV/Z0uuOOzddkczj2qP29kmJli5f31LduCyzreJNzH9 c09KUX/9aNaymJIckKAu9krYNhrEoILsP6RckvI7kw1HZlc3dWU0mRTXbRved/QmHpcw cV9xCu/Wt317gU87+F/fEBC3Kp5IfVFsovxRaEb1wUp/DXdW2y7caxumNpOdm6fzV06P wb0syQvYwhQANVXZjiwy8xn7oC6MbsSFq23a4nkZrs6zFpy1Nw8MN2V4KL8QVx05T8RZ 8EAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/CksNMLgJxQqZTGvVoyYFDLCuLf1sggTOdB/wwyAbMc=; b=O2rzXV2q7Gr1FByUOtdnjv0GNEitj94pcNp04tqa1lzYWkhasIvQBQ24HAo8vKyHjR J2AVnngBRytZFkPPo8fxkpwZhyRRO3KFNnt7qBeTv/6BvwdTieTsTiJDDe3nMf4Bknl3 /v4rnn4jfyzbY/PBqvTJzjwAbKFoLUqmZ3zcQLOasTyUgI/KhEhFecMucRK+lKHgSppg PHCo17orCdobL35E5M5RPO96XtmkbdyEogoWgBCDI6WRvqutQwuzUsrsKlIBr8CDaj5o z9WSFLEgaPiPTOdAT+NcGcMIcwX5yatCdfyAbuiYoq1AosRoqzu34QNG8vOkps/IUz0F bBLQ== X-Gm-Message-State: AOAM533jFrpfGJi9pJ05LnRSZdpTbaNtHzrXHpXc+mj0b3oslwi+xmrH 4MgMhtZlc1oVNXbLvGSP8qksLg== X-Received: by 2002:a19:3811:: with SMTP id f17mr285263lfa.28.1611440368260; Sat, 23 Jan 2021 14:19:28 -0800 (PST) Received: from localhost.localdomain (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id x17sm1313956lfg.0.2021.01.23.14.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 14:19:27 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Lee Jones , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 07/10] power: supply: ab8500: Avoid NULL pointers Date: Sat, 23 Jan 2021 23:19:05 +0100 Message-Id: <20210123221908.2993388-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210123221908.2993388-1-linus.walleij@linaro.org> References: <20210123221908.2993388-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- drivers/power/supply/ab8500_charger.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index 704006bf554c..158131ed8b80 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -415,6 +415,14 @@ static void ab8500_enable_disable_sw_fallback(struct ab8500_charger *di, 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);