Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1145141pxv; Fri, 9 Jul 2021 19:26:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDJH4/C9qnCX+1QH5lPx66CXbcrg9VUZlTg+urmY0RxIzoAxJCdUebKF6ELtR59PbyxgJS X-Received: by 2002:a17:906:698a:: with SMTP id i10mr40384950ejr.499.1625884011488; Fri, 09 Jul 2021 19:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884011; cv=none; d=google.com; s=arc-20160816; b=hTJ3swe7Mno1YfUfTjBtWyLKQPggChAPB0ij7xovKxYhWc0xBO+fEK4oNAqd9ki2a7 NpwNWNb3Z5CbNpA/optdGYS/LruBUaefK89N/Hn4Fu/3Xm886EmVKCbovAHDUyKOuRDm gdlTwKmptkD8Img+v3XFUix3oG3vUIPk1jPGOQ1bCL3dyPbtcDmwFCBCYnF/TzPahRSA 12f5aun8mATUati7sduIwUQlTfek6Qr6INBo09kh/pTVIWeVoVZ5wen0D3H63zF4MJjr 9eLWwH0PDuoQWMaEUZALYUQghQD+ThDVoIbmg+2cLxeZ2qdQJWDmeB+WJWeaGwpS+NG5 u4eA== 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=wtKhJG1KpnTLzgbP1k2WxlSLPBcUwkONB5HSO8rHMQQ=; b=KIPnh0no65q2HVlRdjjvZ3Cwzbvyoh6fjbX68WNe6eDK8ikJJ6doAQ/apP1P1Bcu+P D1P2jJpGVJXlsRi3K5Czoe3+P0bEC90Yt4Pc4LemBxbLv9lQyacv63fDyNt4fKUPXuEW cL/Mngh9JyzKkNmyE9hBtE66imt5965EV71ZaeBbtjeRoVF5fZa7xi71uF9GPS5MlxRj Hk555W36hqzHQyqRh87OrtlF22Owwr7gEHdLof0J22Q+c+mMXlO4gWv+UUYm8aSkLZiH 5ZRQknCgyrKClNxhOgQAlCZxfiMIfSob9NJwo09gz4iHX1jQs9O3/cTouXGTwg1qilS6 wsqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=swyS7SKC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si9133232edc.121.2021.07.09.19.26.28; Fri, 09 Jul 2021 19:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=k20201202 header.b=swyS7SKC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233143AbhGJCZk (ORCPT + 99 others); Fri, 9 Jul 2021 22:25:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:42072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232525AbhGJCZK (ORCPT ); Fri, 9 Jul 2021 22:25:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE2CD613E6; Sat, 10 Jul 2021 02:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883745; bh=N9tg4uOowuFl6i9wi0x5B9WKbHwNGTjWXkUqtqYIuno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=swyS7SKCsqM3yDLRaE2A+hDf1c3nyOkKXW5SX4LsiRAQNumIu9SU7jrLEI1uAT46b 2Zf2p6iceP5WpF8aNqwNTh7Vpyu7kBLMNewDOGtkufegJhQGfV2CF2/9ZToeuFkvZu l8QdhO2lSzOG+0c3S7GQINs/lYK6Jd4Pqyo26b8c0aQjfw4zxyW4K7apa0xdgd6m6f 9xVG+l73kYFv6wPlHI1PFHpMbSkuWE1F2zYqGkqh/eMz5jnmLQwa6BoUg4RDrKCMwL VjdFJ0Dx79LtqXYgw3KnMQa69i4336ta/Mm0SWtvVs8LHnLcqSS7PBfThT7iriCeOR E0Q2u2K/XOolA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chunfeng Yun , Greg Kroah-Hartman , Sasha Levin , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 5.12 022/104] usb: common: usb-conn-gpio: fix NULL pointer dereference of charger Date: Fri, 9 Jul 2021 22:20:34 -0400 Message-Id: <20210710022156.3168825-22-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chunfeng Yun [ Upstream commit 880287910b1892ed2cb38977893b947382a09d21 ] 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 Link: https://lore.kernel.org/r/1621406386-18838-1-git-send-email-chunfeng.yun@mediatek.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 */ -- 2.30.2