Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3081962imw; Mon, 18 Jul 2022 01:33:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1smQCdH335ZbBeZgpfIWIlRRERkk74QpIlnjZ42/26BIZmIl+GYxpmtD32nHCTPp97Vk7qM X-Received: by 2002:a63:1459:0:b0:411:b06f:646f with SMTP id 25-20020a631459000000b00411b06f646fmr23737564pgu.338.1658133227080; Mon, 18 Jul 2022 01:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658133227; cv=none; d=google.com; s=arc-20160816; b=NlPRs0DYSOCyeICRet/MM8C0uVenKLnUQadnONxmxyIXX5tujlwBQgevSQmXk05kAJ F0dLz840zKorkAhrDre22O3iKQtGez0JE0duuVrpGkndC2fICF+cLNKwbzQcwEWishF6 eRJA68AgAxGMlJEcu4GYA5ZSPEPBA2B3UM02iuknezZGu8ffev/Po9ZWRGEAs4k/cbFC D+OBlUg4rRZuYIocvWnBmxy1GRGSBnmyqQyA44h/Qo4K1nNChbuIMEve1I0lpkOqSS0X NJpynOpzfprE/CqcmCnB4Mx66rzCgiG3xEtfnUHcnKIYeDj3AqQ1RIf4e+5LtVjoyAzV Db/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CUvUySPFulLpJMe6eEU3YtP+k2lXPFdi238dz02/TnA=; b=F2Gb1LQHWe1neHanawokZh3k0X5X8wJdpFtFh5QG8A7N8xHgB1wxc4Ha75zsoh/0g2 MkRwBZOQbWrh7hLhZ2fHbky3kvUYe7DV1IbRfT4qNaEsQxO4t0hEaZd+Qew+oGDJ0vNV lPQwvnfs14n5F4olTaVgLNxbJZjbutGFDc1y5DtHnLl5HcLDjY3NzjxEtGX+qhJud8Uc RZlPTvhqU8ErxlXWXpvzNcXOqAYqf7NVvlosaazcz/IhHCttr9oRjBKKWKFl7HE7BG2L 4zsjBPbCywJP5hobWPxGmvHbiu1RXFSwWsmvwr81TC1v/pvEWfaUdgHqEVBB/U8LBk8L JwHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pHUAhFih; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a056a0022d000b0052899a8f770si16500073pfj.174.2022.07.18.01.33.31; Mon, 18 Jul 2022 01:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pHUAhFih; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230240AbiGRIIx (ORCPT + 99 others); Mon, 18 Jul 2022 04:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233640AbiGRIIu (ORCPT ); Mon, 18 Jul 2022 04:08:50 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3010398; Mon, 18 Jul 2022 01:08:49 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id g17so8344110plh.2; Mon, 18 Jul 2022 01:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CUvUySPFulLpJMe6eEU3YtP+k2lXPFdi238dz02/TnA=; b=pHUAhFihwGq4x+L9IFz64byctPKxMey+1jJrxWMXoIp6tYfspwIQNIMzp7YBTH00xn MRzfhJj8RY4NA4mFvpX/dCVWMpW27h/Njmzv7MmAtFUvpbbul8t5EAe192JoL/OYQ6/s zYjE+CbBzxnhn/cgTyA0Bs/GtDn+R9lbkor0iXsp+EmPI2KlVUjcMQTUQrIikQ8NHDMp I2FQM1xubPFVtXGRB4dZts8UYYxW5QU7vg2DfZS27wC41UjIJhTXDckFd8tPgOzwbvc4 1cKXpRAi5A/FWLrXPzcBSgixvnKv1XZEewB7e2CcmvZHXmuVo8UORFDuotPcS3/M7CCo WblQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=CUvUySPFulLpJMe6eEU3YtP+k2lXPFdi238dz02/TnA=; b=NaV9C/9iP7f14brAMCMAj4H68r7cOQ+N3atVFhoxoXZXC2UvZDipnM8c2ezgcvcbKq XODfQfMsK4u4/Wqs1gD4z0h8OwG6bG4dGCrvO+vqONlNOSc8iUge+7pvFYJcgJt8q9RP f8eosfJQdwe0IKPd755nBOuIIe3QmBkHhB4ZfRldgaQpKz+etTkl6SIP5APPJwl4YEuP 2m8c/IHVHpUPgayBue11gDd1PtRdLnXC/9sIH5h9utAxkcFrrV1qm6G0OdKo6Gdv3G/m gLwcHeLugUkEgy2sNYFwgHS3gVnwY7piA2F7Pd+ux3lhkNKjGiiaAing+P4HWI43sTN3 ujRA== X-Gm-Message-State: AJIora9anOqwnk4HSMI+1IFDl6yGnK7b8grZHO1ZBucM0rDamNVjn1h0 hPSIkDNNSKqjN3OfXmFg9P0= X-Received: by 2002:a17:902:e888:b0:16c:33f7:89cb with SMTP id w8-20020a170902e88800b0016c33f789cbmr27448255plg.2.1658131729130; Mon, 18 Jul 2022 01:08:49 -0700 (PDT) Received: from cyhuang-hp-elitebook-840-g3.rt ([2402:7500:587:e7ad:4982:5f13:5219:614d]) by smtp.gmail.com with ESMTPSA id u9-20020a170903124900b0016cabb9d77dsm8895028plh.169.2022.07.18.01.08.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2022 01:08:48 -0700 (PDT) Date: Mon, 18 Jul 2022 16:08:35 +0800 From: ChiYuan Huang To: Andy Shevchenko Cc: ChiaEn Wu , Lee Jones , Daniel Thompson , Jingoo Han , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Matthias Brugger , Sebastian Reichel , Chunfeng Yun , Greg Kroah-Hartman , Jonathan Cameron , Lars-Peter Clausen , Liam Girdwood , Mark Brown , Guenter Roeck , "Krogerus, Heikki" , Helge Deller , ChiaEn Wu , Alice Chen , cy_huang , dri-devel , Linux LED Subsystem , devicetree , linux-arm Mailing List , "moderated list:ARM/Mediatek SoC support" , Linux Kernel Mailing List , Linux PM , USB , linux-iio , "open list:FRAMEBUFFER LAYER" , szuni chen , ChiYuan Huang Subject: Re: [PATCH v5 08/13] usb: typec: tcpci_mt6370: Add MediaTek MT6370 tcpci driver Message-ID: <20220718080831.GA31509@cyhuang-hp-elitebook-840-g3.rt> References: <20220715112607.591-1-peterwu.pub@gmail.com> <20220715112607.591-9-peterwu.pub@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 15, 2022 at 03:10:42PM +0200, Andy Shevchenko wrote: > On Fri, Jul 15, 2022 at 1:28 PM ChiaEn Wu wrote: > > > The MT6370 is a highly-integrated smart power management IC, which > > includes a single cell Li-Ion/Li-Polymer switching battery charger, > > a USB Type-C & Power Delivery (PD) controller, dual Flash LED current > > sources, a RGB LED driver, a backlight WLED driver, a display bias > > driver and a general LDO for portable devices. > > > > This commit add support for the Type-C & Power Delivery controller in > > This commit add -> Add > Upper case? Or rewrite it as 'This commit is to add .....'? > > > MediaTek MT6370 IC. > > > > +static int mt6370_tcpc_probe(struct platform_device *pdev) > > +{ > > + struct mt6370_priv *priv; > > + struct device *dev = &pdev->dev; > > + int ret; > > + > > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > > + if (!priv) > > + return -ENOMEM; > > + > > + priv->dev = dev; > > + platform_set_drvdata(pdev, priv); > > + > > + priv->tcpci_data.regmap = dev_get_regmap(dev->parent, NULL); > > + if (!priv->tcpci_data.regmap) > > + return dev_err_probe(dev, -ENODEV, "Failed to init regmap\n"); > > + > > + ret = mt6370_check_vendor_info(priv); > > + if (ret) > > + return ret; > > + > > + priv->irq = platform_get_irq(pdev, 0); > > + if (priv->irq < 0) > > + return priv->irq; > > + > > + /* Assign TCPCI feature and ops */ > > + priv->tcpci_data.auto_discharge_disconnect = 1; > > + priv->tcpci_data.init = mt6370_tcpc_init; > > + priv->tcpci_data.set_vconn = mt6370_tcpc_set_vconn; > > + > > + priv->vbus = devm_regulator_get_optional(dev, "vbus"); > > + if (!IS_ERR(priv->vbus)) > > + priv->tcpci_data.set_vbus = mt6370_tcpc_set_vbus; > > + > > + priv->tcpci = tcpci_register_port(dev, &priv->tcpci_data); > > + if (IS_ERR(priv->tcpci)) > > + return dev_err_probe(dev, PTR_ERR(priv->tcpci), > > + "Failed to register tcpci port\n"); > > + > > + ret = devm_request_threaded_irq(dev, priv->irq, NULL, > > + mt6370_irq_handler, IRQF_ONESHOT, > > + dev_name(dev), priv); > > + if (ret) { > > > + tcpci_unregister_port(priv->tcpci); > > This is wrong. > You mixed devm_ with non-devm. Either drop devm_ *after* the first > non-devm_ call, or convert everything to be managed. > How about to add 'devm_add_action_or_reset' for tcpci_unregister_port? This will convert all as 'devm_' version. > > + return dev_err_probe(dev, ret, "Failed to allocate irq\n"); > > + } > > + > > + device_init_wakeup(dev, true); > > + dev_pm_set_wake_irq(dev, priv->irq); > > + > > + return 0; > > +} > > + > > +static int mt6370_tcpc_remove(struct platform_device *pdev) > > +{ > > + struct mt6370_priv *priv = platform_get_drvdata(pdev); > > > + disable_irq(priv->irq); > > Why? > An ugly workaround due to ordering issues in ->probe()? > Yes, due to the ordering in probe. 'bus remove' will be called before device resource releases. Like as you said, another way is to convert all as non-devm version after 'tcpci_unregister_port'. If to keep the original order, 'disable_irq' before 'tcpci_unregister_port' can make the flow more safe. Or you can think one case if irq triggers after 'tcpci_unregister_port'. Null pointer occurs. Anyway, in next revision, I'll convert all to be 'devm_' version. For this remove callback, only 'dev_pm_clear_wake_irq' and 'device_init_wakeup' will be kept. Is this better? > > + tcpci_unregister_port(priv->tcpci); > > + dev_pm_clear_wake_irq(&pdev->dev); > > + device_init_wakeup(&pdev->dev, false); > > + > > + return 0; > > +} > > -- > With Best Regards, > Andy Shevchenko