From patchwork Wed May 19 06:34:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunfeng Yun X-Patchwork-Id: 12266421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B80AC433B4 for ; Wed, 19 May 2021 06:47:14 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1109D610CD for ; Wed, 19 May 2021 06:47:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1109D610CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=cTdseO6esVBm/tsGUOFBg/Xn4rsFJi1BP7Wo8asBe7o=; b=fJSRiyB4zkJgbbS0TjPPgnjQN7 lpuwf4q6OJr3Ulzhw3zbAVGM3wesZ5zGAPbMHwVN1tEpSb64ZS/ledHJpXmziFJrMz5ikGfPtYMae Pg533doYx6Oi5sFfLAyRSdpE7L6iUPSh/uVKTYl+WzqySBGYa0F66uaRs28KToYscRUYKHKaEOX4k lJlzGt1MAE7dupQHSdWF+wqUheCGfujI/L2lhkZgiwhnssh30F0feHJrdv5SjJXJHxvj+EpLFvwHg EVQ9dCaB3ZESSFd2nO0KnYTsX3GvL08pCdzI8yiHtCkXRof7P0CndeHV/zD8/+Mx+hkPxQBKulRSr KCbCJO/A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljFwi-00322a-Bh; Wed, 19 May 2021 06:44:44 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljFwd-00321q-Hw; Wed, 19 May 2021 06:44:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-ID:Content-Description:In-Reply-To:References; bh=8z++B8XVLCARu24JUi0rTZSYSrWtbXfC5DOMZvKLaJ4=; b=sMYODdC8N4WJPBecB86aUuImyV hkg6CqUoRB8M+9xb+nVby7Q/t0AR9rGoIv0mva8R2hiU4ygleZd8AFi/qMsgdwEhXZIV5bNtnWd3e qA00nqZuEWr5dgT2zzJSLIgc77GtUzV8ttlGFnQzfyrAMWDLW26YMMTUKNa+yBH/FzoDQsZyB0WXu JMcAHf+rZkfvlmKZDCFVWOoXEMPoGu68B4H2o8fv5yASz5pYhsHOGgvLa+BM1kMD/eHxQuvZRtIbw R+21LXyYYiwYWhlG+aTZgCsirrQ19d48v2Blht3G+YHOhUw41QhauMtPKNDzZJfaBpU9tN9YNOQ5V f4yc4wkQ==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljFwa-00FBni-VB; Wed, 19 May 2021 06:44:38 +0000 X-UUID: 0fed63a3924e4d57b510175f88a1b383-20210518 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=8z++B8XVLCARu24JUi0rTZSYSrWtbXfC5DOMZvKLaJ4=; b=K8jje7riaa8K9W+veRlDF7Ug/SbjQOJ7MOTcJ0a1IzBGYE5B8bs7XtMKI8y/cHkhoc0NnU4tbbWgRuxk6PzZhilhF++cn+siB8UQ+tYUTj8vfS5FbZ5YKesqk10+cuC3Kep+OagVQMKhqjM0Ll+7wZmXRNk37yW4Yo58DS6qeyo=; X-UUID: 0fed63a3924e4d57b510175f88a1b383-20210518 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 303085790; Tue, 18 May 2021 23:44:28 -0700 Received: from MTKMBS31N2.mediatek.inc (172.27.4.87) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 May 2021 23:34:26 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by MTKMBS31N2.mediatek.inc (172.27.4.87) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 19 May 2021 14:34:17 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 19 May 2021 14:34:16 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Thierry Reding CC: Liam Girdwood , Mark Brown , Matthias Brugger , Chunfeng Yun , Paul Cercueil , Lee Jones , , , , Subject: [PATCH 1/3] usb: common: usb-conn-gpio: fix NULL pointer dereference of charger Date: Wed, 19 May 2021 14:34:13 +0800 Message-ID: <1621406055-18749-1-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty MIME-Version: 1.0 X-TM-SNTS-SMTP: 53867D13806BE60B2B21A7355853E7694597F6E76BB9D625F402C7EDB8800A432000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_234437_038428_9924D764 X-CRM114-Status: GOOD ( 18.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When power on system with OTG cable, IDDIG's interrupt arises before the charger registration, it will cause a NULL pointer dereference, fix the issue by registering the power supply before requesting IDDIG/VBUS irq. Signed-off-by: Chunfeng Yun --- drivers/usb/common/usb-conn-gpio.c | 44 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c index 6c4e3a19f42c..c9545a4eff66 100644 --- a/drivers/usb/common/usb-conn-gpio.c +++ b/drivers/usb/common/usb-conn-gpio.c @@ -149,14 +149,32 @@ static int usb_charger_get_property(struct power_supply *psy, return 0; } -static int usb_conn_probe(struct platform_device *pdev) +static int usb_conn_psy_register(struct usb_conn_info *info) { - struct device *dev = &pdev->dev; - struct power_supply_desc *desc; - struct usb_conn_info *info; + struct device *dev = info->dev; + struct power_supply_desc *desc = &info->desc; struct power_supply_config cfg = { .of_node = dev->of_node, }; + + desc->name = "usb-charger"; + desc->properties = usb_charger_properties; + desc->num_properties = ARRAY_SIZE(usb_charger_properties); + desc->get_property = usb_charger_get_property; + desc->type = POWER_SUPPLY_TYPE_USB; + cfg.drv_data = info; + + info->charger = devm_power_supply_register(dev, desc, &cfg); + if (IS_ERR(info->charger)) + dev_err(dev, "Unable to register charger\n"); + + return PTR_ERR_OR_ZERO(info->charger); +} + +static int usb_conn_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct usb_conn_info *info; bool need_vbus = true; int ret = 0; @@ -218,6 +236,10 @@ static int usb_conn_probe(struct platform_device *pdev) return PTR_ERR(info->role_sw); } + ret = usb_conn_psy_register(info); + if (ret) + goto put_role_sw; + if (info->id_gpiod) { info->id_irq = gpiod_to_irq(info->id_gpiod); if (info->id_irq < 0) { @@ -252,20 +274,6 @@ static int usb_conn_probe(struct platform_device *pdev) } } - desc = &info->desc; - desc->name = "usb-charger"; - desc->properties = usb_charger_properties; - desc->num_properties = ARRAY_SIZE(usb_charger_properties); - desc->get_property = usb_charger_get_property; - desc->type = POWER_SUPPLY_TYPE_USB; - cfg.drv_data = info; - - info->charger = devm_power_supply_register(dev, desc, &cfg); - if (IS_ERR(info->charger)) { - dev_err(dev, "Unable to register charger\n"); - return PTR_ERR(info->charger); - } - platform_set_drvdata(pdev, info); /* Perform initial detection */