Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp72365pxj; Thu, 20 May 2021 04:52:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1zF21f0xvz5kBJIiFLcHMTn4+1gyZO5pd0Clg6dt31h+dtDjS4LkqLU1rHtxRvZ4ZXPcX X-Received: by 2002:a05:6402:2788:: with SMTP id b8mr1408338ede.335.1621511531187; Thu, 20 May 2021 04:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621511531; cv=none; d=google.com; s=arc-20160816; b=VZVo9qjBgOoTG4c21ovvwP3jYxKSuxCSZdcI8n2icVFOk62Qk7nBkT0WLKgYX1Uom7 H82L7vFkxXHNQUVpe3K81/UcrCeAGDq8IKKCdKy3Ta5RyAVdp3MqbuXw7iDZqEQXNtz3 Q4qMGJ0LP4g3RtMe15TrCXr5nGcNJevBBf4OuYQpREJs7MmW2kjgPwNBEpmaA0AQ5X39 ekx42N8rm166MNJPMxumwvjcsI5jp8Dpnn5pOkbiRJ4MVH9i6K5DC+8R+YrGAEBuKWCd zbk0T28Kqz5ZZNxWWxUBn1cwVEKMRJ5vxyOtyIjMBBtE9yxrv/CEc4ouh8js2wWPQs6A JtgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7QyAz/Y7sojLhm4WGgiSHyG7ZKRB6TQwfwV5kBelVWI=; b=iiSLkW4FTGW+WV2kow7N2trf4nzmn1g2yPDGapK44o3ia9mlVy9Bx6bgx6rAfUt2cb oNn5C7uILlX/G7B6WZf3y9pjjiqqex2aYpaiH4CcvomNxM4luOjdKtGnsHSYW5k+wKpZ ZxqkNChlPsz5sBSAfAkdqWLubR5z/fU+4ojv9L3Xiv4l28buCjqP8D+k/2V8NHiTp3LO CzOFyd5ZfdiOQPH3sf8lTTe8VAaNB5X9SXRxzoZ8O7YZurmFBH/3BqzLA8iQCANzvc3g ImJrg1Oab3IqSWgX3hIzsFKVx2rPM5b8L/B01q0NE53zqz0hr0l8YSMQVVgPBtmNBKKB 74Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b="HM0C/fxg"; 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=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si2146278edv.108.2021.05.20.04.51.24; Thu, 20 May 2021 04:52:11 -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=@deviqon.com header.s=google header.b="HM0C/fxg"; 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=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243078AbhETLtF (ORCPT + 99 others); Thu, 20 May 2021 07:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240145AbhETLZ5 (ORCPT ); Thu, 20 May 2021 07:25:57 -0400 Received: from mail-ua1-x936.google.com (mail-ua1-x936.google.com [IPv6:2607:f8b0:4864:20::936]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C2B0C035430 for ; Thu, 20 May 2021 03:06:43 -0700 (PDT) Received: by mail-ua1-x936.google.com with SMTP id x1so4858004uau.1 for ; Thu, 20 May 2021 03:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7QyAz/Y7sojLhm4WGgiSHyG7ZKRB6TQwfwV5kBelVWI=; b=HM0C/fxgCgP9PqpIBs5RDFfOToJmqVddEeDOSQdQiFAZ0XmNj8tPrwEkz+wAzTxKbL 9wM1LXUkA4xetjxn3/1N8FZgv060Y/XtU52d2O98mkHuJi93Je4nJXZ5KvaglO3xm1L3 OC2mdYuBizLnhryJnABFdzoaW3hXnWa/gyCyeW/FZp19piowNWF+9FgaGN65jrsK5TkF dwougd3a+a7hBIcQHMjLDVR2Q4uhQlsPwAgVhHLjrCw+zP9fj/3oZyCfD2y457RhS0CR 5bv3I1jYwawTDKdpiI4d7rjBQc1JtfDQZUKdKEgzgZqgmQlGi8PlX1uE8aovFyL0HzLo 4zkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7QyAz/Y7sojLhm4WGgiSHyG7ZKRB6TQwfwV5kBelVWI=; b=YEOq6gQc9JZ0arxJgMQ3OIwma0xtMk7O6u/TBMvoed39XL3jEmWBpOOA88o/cb8Jdh iF/kEA1cWSv2vdbox1t/23ZDD1/3ZcHn1LBiWbTZazLHtcUq9mc8T9EBbzgUW5VDEXch VmYmWFCig38DkK4iryfTxsqQkKShfSXIckpZCsvy34WvmquopXfHifLwqbxXQxW6HhIJ jH1QFVAPxxzbow0bUDrD3HV59LzTrneLFtuB0xHvs85toMRWCxhmcba6H2J18cS4zRVr JssL0hsLGG++zP2bzsu88EaBAGUx05XcGfR1HejoIRJcGbkqcJYxEK6YIv26/Ofhhv51 sUbQ== X-Gm-Message-State: AOAM530RLLxDmDDDvyS3gat3eOPutfajwq0NoNYaO+Yd6LolH7CEWezI IPDkKiN3vpIU6gNV62aRoflxBVecXmrm9uav1uJFcQ== X-Received: by 2002:ab0:14ce:: with SMTP id f14mr3285015uae.50.1621505202313; Thu, 20 May 2021 03:06:42 -0700 (PDT) MIME-Version: 1.0 References: <20210516061425.8757-1-aardelean@deviqon.com> In-Reply-To: From: Alexandru Ardelean Date: Thu, 20 May 2021 13:06:30 +0300 Message-ID: Subject: Re: [PATCH] gpio: gpio-stmpe: fully use convert probe to device-managed To: Andy Shevchenko Cc: "linux-gpio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linus.walleij@linaro.org" , "bgolaszewski@baylibre.com" , "alexandre.torgue@foss.st.com" , "mcoquelin.stm32@gmail.com" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 20 May 2021 at 09:40, Andy Shevchenko wrote: > > > > On Sunday, May 16, 2021, Alexandru Ardelean wrote: >> >> The driver doesn't look like it can be built as a kmod, so leaks cannot >> happen via a rmmod mechanism. >> The remove hook was removed via commit 3b52bb960ec6 ("gpio: stmpe: make >> it explicitly non-modular"). >> >> The IRQ is registered via devm_request_threaded_irq(), making the driver >> only partially device-managed. >> >> In any case all resources should be made device-managed, mostly as a good >> practice. That way at least the unwinding on error is happening in reverse >> order (as the probe). >> >> This change also removes platform_set_drvdata() since the information is >> never retrieved to be used in the driver. > > > Any driver can be unbind from device thru sysfs. The exception is when they (device drivers) specifically disable that. Oh, I see. Thanks for the info :) > >> >> Signed-off-by: Alexandru Ardelean >> --- >> >> I'm not sure if this should be marked with a Fixes tag. >> But if so, it should probably be for commit 3b52bb960ec6 (also mentioned in >> the comment above). >> >> drivers/gpio/gpio-stmpe.c | 32 +++++++++++++------------------- >> 1 file changed, 13 insertions(+), 19 deletions(-) >> >> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c >> index b94ef8181428..dd4d58b4ae49 100644 >> --- a/drivers/gpio/gpio-stmpe.c >> +++ b/drivers/gpio/gpio-stmpe.c >> @@ -449,6 +449,11 @@ static void stmpe_init_irq_valid_mask(struct gpio_chip *gc, >> } >> } >> >> +static void stmpe_gpio_disable(void *stmpe) >> +{ >> + stmpe_disable(stmpe, STMPE_BLOCK_GPIO); >> +} >> + >> static int stmpe_gpio_probe(struct platform_device *pdev) >> { >> struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); >> @@ -461,7 +466,7 @@ static int stmpe_gpio_probe(struct platform_device *pdev) >> return -EINVAL; >> } >> >> - stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL); >> + stmpe_gpio = devm_kzalloc(&pdev->dev, sizeof(*stmpe_gpio), GFP_KERNEL); >> if (!stmpe_gpio) >> return -ENOMEM; >> >> @@ -489,7 +494,11 @@ static int stmpe_gpio_probe(struct platform_device *pdev) >> >> ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO); >> if (ret) >> - goto out_free; >> + return ret; >> + >> + ret = devm_add_action_or_reset(&pdev->dev, stmpe_gpio_disable, stmpe); >> + if (ret) >> + return ret; >> >> if (irq > 0) { >> struct gpio_irq_chip *girq; >> @@ -499,7 +508,7 @@ static int stmpe_gpio_probe(struct platform_device *pdev) >> "stmpe-gpio", stmpe_gpio); >> if (ret) { >> dev_err(&pdev->dev, "unable to get irq: %d\n", ret); >> - goto out_disable; >> + return ret; >> } >> >> girq = &stmpe_gpio->chip.irq; >> @@ -514,22 +523,7 @@ static int stmpe_gpio_probe(struct platform_device *pdev) >> girq->init_valid_mask = stmpe_init_irq_valid_mask; >> } >> >> - ret = gpiochip_add_data(&stmpe_gpio->chip, stmpe_gpio); >> - if (ret) { >> - dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); >> - goto out_disable; >> - } >> - >> - platform_set_drvdata(pdev, stmpe_gpio); >> - >> - return 0; >> - >> -out_disable: >> - stmpe_disable(stmpe, STMPE_BLOCK_GPIO); >> - gpiochip_remove(&stmpe_gpio->chip); >> -out_free: >> - kfree(stmpe_gpio); >> - return ret; >> + return devm_gpiochip_add_data(&pdev->dev, &stmpe_gpio->chip, stmpe_gpio); >> } >> >> static struct platform_driver stmpe_gpio_driver = { >> -- >> 2.31.1 >> > > > -- > With Best Regards, > Andy Shevchenko > >