Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1758523pxj; Sun, 16 May 2021 03:20:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIMaPRo48RjMWpo5JObhA2b+1wlZdzvBawysj9+QovaIEVK7kwRSt90gbuNU2fjtR0icTG X-Received: by 2002:a17:906:4089:: with SMTP id u9mr3598141ejj.18.1621160413777; Sun, 16 May 2021 03:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621160413; cv=none; d=google.com; s=arc-20160816; b=nIz/2mtQxJDkkXhdR2yPjHomgOaYz0l7WfFTp+S11d1IRXF57gFGzHZgZS7bvCt1Sd uKX5+vQuyDYSrPvot/4hHHZ+43lYgCPeAqRYJqKaDOAyGuaZoZDfiTjrB2etD/g4gqEN 2x8hBrWrmEMyCSk5XVlzaNLc4+VerEARgthnspnrrbS5E5ePAIltfUwwEhd7134iSafx Ep+m556Z7v5mG7SfDLL6Aiqj+0VYVr2WHotmUeMkNtC82n6WF5IIHzahmM9lgEXrJs3w KruCdN8t7t3SwsWfuK7oGsQZ35bDUKSgBQgKWOMfU2tAGjQ/Q05iDzmFs4T4+l05we9M 0GaA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=hV6WC5eXV3av99h5LQGXtV8+/Xaf5pHoRp9Aw3md/WM=; b=J5vlyOhAGE5Y6nv96ViIsLuHgfYTwdlR9mmf7/wbfE6v8cjsx177Jh8NTEI3xEoual 7Ot1o+nYHr4zdJqUVeODv/p3WkXWHLYHUJhLnEYdIhmkS+kbfpFGaAvXYA9XcZx3+JNi uL7r4sV/RrmJTWuPVyCkh/dM7KZJc002GkGqneadzalOZ/F//2oNdILFCYMIbMfjiioJ ewnZT/FEJPs1RZ3ufq6UQPNheUYi6UZiPX+Fo2Fuudd3lZ/+9d+hPaQTFI8ydIq579Co lyQxVRDq/UiAjPINOn7qHaz7nlaCGh9hk+1QH3xR5jrOVlmaVZEV1cL0N8aRn91I7iUO TjVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=JHWFZpaY; 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 nc38si13302043ejc.570.2021.05.16.03.19.50; Sun, 16 May 2021 03:20:13 -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=JHWFZpaY; 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 S233214AbhEPGPs (ORCPT + 99 others); Sun, 16 May 2021 02:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbhEPGPr (ORCPT ); Sun, 16 May 2021 02:15:47 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A806C061573 for ; Sat, 15 May 2021 23:14:33 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id t15so3039341edr.11 for ; Sat, 15 May 2021 23:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hV6WC5eXV3av99h5LQGXtV8+/Xaf5pHoRp9Aw3md/WM=; b=JHWFZpaYDyH2S+nfvWPrjJ7qqGLtUODW2nWSddvpDV0IER1StHfyf8OcwKfETSUiHh CT7Rd082zmRHz9vzOVExuL2VsKE8YCXYK2CqdiPhWAqwQNZsz8hMGxLpknuwKcIsx1bm SKgloSZxbfQRU40fB155fgFDfCJboC+EcSxUSe+0I0nxz0VDeuvLi5HTAjJCHCSeyT/z Vt7dRgMuNIzAWOMX2lyz3TVefBorXinezt8JOv1zNvRaRVOrXrj+/qU2Z3DDEO5GaKaN w4FemDuaSwOQpe8F195SyCX0KrHNGeYu7b0ol8o5+xiP7uLIGYnosBDS1g8OGIJ/n311 o0Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hV6WC5eXV3av99h5LQGXtV8+/Xaf5pHoRp9Aw3md/WM=; b=jlibh9vjbRuO09DsGdjwr9jGna34htO8iRKP+Iv/SNVFf3iAG7YmIlXTjR55IUZpnq zDYBzyHJKsQv/mMIkGnGUwoKi/YYRa2/ICQa0zsBr+Cgpiurcdhy4OrZ9ajZVfpinnTZ 7AZ96+/xbSjPOCPHwzdc03tW4+dleWVotWUXqRBFkGej0oW266Tr4mMml7asHp3Klnbu TfuQ1eVQoqcaBI/vZmSzSEVo3AqPoEpC6p7JVsloDND1uzUjIMFk+rru7F2ADFOBG7Pk zkxA1zIQu9f2wjT0ZAM3BbvADbhb8ZM15PtfiMCZ0l5cO8zE/jYu9Z769Qic6387YE8r mpZQ== X-Gm-Message-State: AOAM530S3bfMhZgK5I605odb3deHF02j+QyJmQJ/aUspx5vYS4u4A/wJ t7xHfxpwuLBO8Fj/GQQIfpIv3w== X-Received: by 2002:aa7:cc10:: with SMTP id q16mr44692153edt.53.1621145671931; Sat, 15 May 2021 23:14:31 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id o8sm6396615ejm.18.2021.05.15.23.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 May 2021 23:14:31 -0700 (PDT) From: Alexandru Ardelean To: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, bgolaszewski@baylibre.com, alexandre.torgue@foss.st.com, mcoquelin.stm32@gmail.com, Alexandru Ardelean Subject: [PATCH] gpio: gpio-stmpe: fully use convert probe to device-managed Date: Sun, 16 May 2021 09:14:25 +0300 Message-Id: <20210516061425.8757-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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