From patchwork Sat May 22 22:50:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 445913 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp2151645jac; Sat, 22 May 2021 15:53:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTikggWyJ7qmF9RXDedV7KDwPcedH4jvCdf/F/DWa/AQaD4Ga0FsZZ5detNTVAo1sd9eI4 X-Received: by 2002:a92:c56a:: with SMTP id b10mr6342367ilj.17.1621724014181; Sat, 22 May 2021 15:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621724014; cv=none; d=google.com; s=arc-20160816; b=uDLgg5AOS1yCziASClSamkmqsyPR/My7UMAnaN/hTMfQ2XH0KsORsOdfftrw0wRZB3 hAutOzjyZP1N0NREDMqYVHt/Rmb2LPC0Rx6ygMItT7edAXyKOlpu4e3DCGnj7DLu02eW r+pcwdQIaMkQiZ/BZfympXBPyPLJHI/YowiK1j/ThpUU4htrN4TNXh91XWXbZ5IKsnsA yDV2nlvUXE+AJN+l/x4OVyO2vxkWbF7ISuWZiKaZqhJ2FScuYWe5qtNbf0u9D/maVjLn G2sWkHbzZgpc7IYBwgBw336LJYcfM/WK/74W4iUj5Aphv+bakLsX5cc6kvEKBqPAzvu/ wd2g== 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=or/aJ9cUCVlgkGbVDYelKbGCCFYUXfIWIGVlXfrFOGk=; b=B+uXyGWrE3EaDrNlw7Nns7PqutA9GFzaCOxcYEwyMWqJYCOn7Iu1qFxJVvur6sYrbk zAsBApdH2YI4fa0bVZ7pN+NASN0xiRFKAfjucrAivqMrt1XT7oTp9UTP/Xyn1ta5J8ic GH+tYi623icbCwWknknIL7PFoqJZOA9g17HH4vBdAS4vGXgQ44mC6D2PF0KKeQ6FewrQ 4iYReae0tnk9igcU1w0w+jvTvBxh9EWXtzLmHvEM/KsOQTI+DntkseWCxOU0l8OUg3Y7 RfRx2B8noYEZNTSMHlO5PTmiYfr02/9nSiJBFH87mk4tPAoNuTkeQC295vZFdpegKc0B bOqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gjm1qswY; 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 b4si7812272ioz.1.2021.05.22.15.53.34; Sat, 22 May 2021 15:53:34 -0700 (PDT) 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=Gjm1qswY; 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 S231447AbhEVWy6 (ORCPT + 8 others); Sat, 22 May 2021 18:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231433AbhEVWy6 (ORCPT ); Sat, 22 May 2021 18:54:58 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE2DC061574 for ; Sat, 22 May 2021 15:53:32 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id f12so28520195ljp.2 for ; Sat, 22 May 2021 15:53:32 -0700 (PDT) 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=or/aJ9cUCVlgkGbVDYelKbGCCFYUXfIWIGVlXfrFOGk=; b=Gjm1qswY/38QE5k6L+n/6DRp+oyPhknR0nEBnzwLAxu0hNnNDu6YVF6nmjRMzPN0n/ hWOQID1AM26H2f+DejxOHDt+7dQYkc91ySfz0VNjMKCNAaoD4VsfIR7ZrXSGgtIu9uM8 j5I6QO1VYL7wDMXqAlWkTNQfStws3NekYIRTsxrjZVlu7kzbCQ4mbRbQLDqoASsrAMIs Ot728tVSiAouk435cke/0fh1uH7Rz6JVwUtvfRf/0wcMbS7dTVlXL3RdJjjOCkmeLGYL LUkBxi8oVcbp0fmznjXONbmu85NP3IfX02txSNlBcYAGxAz1EfXl5XP+bVZyk7aHz9AO OmXg== 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=or/aJ9cUCVlgkGbVDYelKbGCCFYUXfIWIGVlXfrFOGk=; b=Z/7baY+bYEmYu2jMdIpyKDJQzfYjG8C3IH++v/1XI5noDBA22wT01rw2h/Lh53Fuu2 00T4KRWy61KwUumZMfUSY7MGkfcJ43QZ7/y6J0KoCMQaV4nmHDgJa8jX1ZJ4fklNkv/M rCK9gyKoPXWdkgEoaGMyVapCTE2MburV1b18uBdHcCNrdP09gxD+s5JNcekDh0grRptW myy6PAt7Xdl9mmjfso+Dte0r5QRBLRCa2iWlLtzuAvl3+sRVnR0zyxBY2soCfdrYODNv CBF7DXhtwlyjnAV9smuZwpX1JO5KOekOOUfzcRvP2tEDfd2JTdcrzOcMF55AbfuvjEdg C+sA== X-Gm-Message-State: AOAM531M0HwjXGKfNl36Wj9UuCXnwdB4pRkaGYeIs1evdsJrF0K/fOjx aG5Y/gRuQjefZXv8Ji64O8L1PA== X-Received: by 2002:a2e:8e66:: with SMTP id t6mr11653034ljk.481.1621724011304; Sat, 22 May 2021 15:53:31 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id p14sm1136883ljc.58.2021.05.22.15.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 May 2021 15:53:31 -0700 (PDT) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 3/5 v2] power: supply: ab8500: Avoid NULL pointers Date: Sun, 23 May 2021 00:50:41 +0200 Message-Id: <20210522225043.1004103-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210522225043.1004103-1-linus.walleij@linaro.org> References: <20210522225043.1004103-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 --- ChangeLog v1->v2: - Rebase on v5.13-rc1 --- drivers/power/supply/ab8500_charger.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.31.1 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 @@ 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);