From patchwork Wed May 19 06:39:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 12266431 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 B9F8EC433ED for ; Wed, 19 May 2021 06:51:10 +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 3AA07611BF for ; Wed, 19 May 2021 06:51:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AA07611BF 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-mediatek-bounces+linux-mediatek=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=475XPZUXHXIdenfwluXyoEeE9/XoVXKValphwvW2J6g=; b=W3lPeL86JlKJtkVIqGY20Fh0aL 9TmNTIP2AIYghpRPN4oBcV3ttPG5BQegVUpjFIwD32qxo66ixwYJfV38b/1HlMZ9ndFe62IOcAnOM Q1aK+M+tW+iF8fIBIqnXUvDJfg9/Fqm4VMjCTsfXq6MNrlRHbiAS2yjuEbdQKregOWx23ggGg1J+E duxDgTtJvKor9TzeVMqMA+87bUX+9W9L1NTL/Yi0Rgy/AdPmJ3sLiWr8Hfx/AeLkrVkVtMYT1LLkv arni/RhMvcvujyiv5YtGAVcXDPm7S7mDKGmucaWF/XsSG4JMC3BbSSxPSeZdrxTU8v6RAPCTQRDPj 740Yp30Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljG2h-00339E-PO; Wed, 19 May 2021 06:50:55 +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 1ljG24-0032z4-R8; Wed, 19 May 2021 06:50:18 +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=Yu9xHamOG4rjVz4F5uxNkjRcn+EEFyADPLMaxANAN50=; b=2/6053q4nCJ0EnDK9VeO5SvSW1 65+sqk9daYo9Bv7GzkXuxMe4PV8ncPxymt12mBlJzxXBj1TKZpIp+F6Qn+Ebo/dRb188EPlGvEr5M DGqCOENaYr/THUuMMh5p/g12dTzuCARQEd8qnpeq6Rt1z2qDN8+7rewybKxHjvuDj3dOKO7piJZev GpQmccvi4EV+CglnEzBo2x9iATfy4WTctAoj6gAVkar3nLl046HVtpuxbdTBdF940eCxRYCUSETGS i6JFonj3JJNzSVkLm+p+cSiuJn/WpkZnfUKsjTXurfaYrciYSdwC0SuupPBg4TA7meAvs0vHnZ+f4 jT6p6law==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljG22-00FC49-83; Wed, 19 May 2021 06:50:15 +0000 X-UUID: 752bcd5ba5144bfa86e736daa248efad-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=Yu9xHamOG4rjVz4F5uxNkjRcn+EEFyADPLMaxANAN50=; b=tiiTYH2gic4Y0E2P8aXq9RooUcTOZxcxNyLFmRsOXxbWFA8/sfY2o9YehToFUQFq4VfEbIMX9PadUK9fa23OhTjR14LEW6C6KRILyhrOhpB6Lku1QCfsQ/BsybubMPlUa2RXe20xQ+qJ9OdCA+jKMRDT0i8x8TXBy/L/tX1Bn7c=; X-UUID: 752bcd5ba5144bfa86e736daa248efad-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 85069077; Tue, 18 May 2021 23:50:04 -0700 Received: from MTKMBS31N2.mediatek.inc (172.27.4.87) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 May 2021 23:39:56 -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:39:53 +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:39:52 +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 v2 1/3] usb: common: usb-conn-gpio: fix NULL pointer dereference of charger Date: Wed, 19 May 2021 14:39:44 +0800 Message-ID: <1621406386-18838-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: DF0E149C1591C14F9E946A4E74FD92CB5C856779CBF27C32AF978A275F8FE3AC2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_235014_339704_3F82BD62 X-CRM114-Status: GOOD ( 18.49 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 --- v2: no changes --- 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 */