From patchwork Thu Sep 29 05:04:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12993496 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C375C04A95 for ; Thu, 29 Sep 2022 05:04:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234403AbiI2FEk (ORCPT ); Thu, 29 Sep 2022 01:04:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233252AbiI2FEg (ORCPT ); Thu, 29 Sep 2022 01:04:36 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 121BFEE2B; Wed, 28 Sep 2022 22:04:31 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id r8-20020a17090a560800b00205eaaba073so306534pjf.1; Wed, 28 Sep 2022 22:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=MC+eI3i/t3K9Sg+2EGrsVaTd5iJWGGfd3bEqBpabEg8=; b=NfU5l7/HjCD7GuH1ULRdff8ER+2hDIJ6pqibCeYUZb+zXyJX5Y+ScIP3OMkflrllJ/ kWe7puQbTcdwmzBxkUjDqrKzCPBAuCwmIo3d62G0mQp2HKP+QKZ4JjWuSsZWobCB0C2v QCSlOkU87NGhwR4A25RD+DU+6jpKGIvytxevXgSn91IVokNPNK+c3vtdQwidLOcn9b1i 1gEAqgBNI/Ko3nipmGGTIifiEi0KZLZgRYtedVs8WS0/ihfKg4sZhqznF6S7l7n5BeNV OIIbJrZ2C5ueFZIU2i4Q7BWk5tBChtU6oX/gK5DF7U6sjhsaxP+VPc389puuLWTtdPat F3PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=MC+eI3i/t3K9Sg+2EGrsVaTd5iJWGGfd3bEqBpabEg8=; b=Pc17IPs6k4hglLMT2eYfMI4ZZqWtkY/Zej/bYFVWuXdI8j7jOhb0IkKfHYUJK3tNGL HNxXTCCWR357VzrfYPdvsswF/fx2IDW5WNhCeKQm0wn3Sk3iRNGDAEqPhzneomFPvzsU ffyxK9NF5N+VdeHtCewO3yK4uuj9Op2Sz/rCyTBzvdvZF5f35+DlCeuNW466jJOau/BT 69epSY/UVBCgQH9G2NfRfXvZ4Mj2QiM9YmqazBN5U6IshfeFi45btHaNRjpknUwibM9j 6VNBMhGNRQIcnt3XIOyPyyG2vEuQcsDOytj7NSDnQUrrNmyAL96JyUJvOZ1JoPubtBsy F4Cw== X-Gm-Message-State: ACrzQf2HBUOWjB5JltnSWUA1diGR7PMUGC8JjCir2jDJXnydepCCpinD cYSPhfG9on/dGE4tLxRWDwY= X-Google-Smtp-Source: AMsMyM5rOVFb4ynre9HopT1jJsgN4ddXCwc8yTdodHFoxR+3Veih0rzdqSYyGBwPBfLZsFC7iQ9iWg== X-Received: by 2002:a17:90a:6887:b0:203:5861:fc5d with SMTP id a7-20020a17090a688700b002035861fc5dmr14561604pjd.132.1664427870380; Wed, 28 Sep 2022 22:04:30 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:637c:7f23:f348:a9e6]) by smtp.gmail.com with ESMTPSA id ij25-20020a170902ab5900b00179f370dbe7sm4314330plb.287.2022.09.28.22.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 22:04:29 -0700 (PDT) From: Dmitry Torokhov To: Krzysztof Kozlowski , Krzysztof Opasiak Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/2] nfc: s3fwrn5: fix order of freeing resources Date: Wed, 28 Sep 2022 22:04:25 -0700 Message-Id: <20220929050426.955139-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Caution needs to be exercised when mixing together regular and managed resources. In case of this driver devm_request_threaded_irq() should not be used, because it will result in the interrupt being freed too late, and there being a chance that it fires up at an inopportune moment and reference already freed data structures. Signed-off-by: Dmitry Torokhov --- drivers/nfc/s3fwrn5/i2c.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c index f824dc7099ce..fb36860df81c 100644 --- a/drivers/nfc/s3fwrn5/i2c.c +++ b/drivers/nfc/s3fwrn5/i2c.c @@ -231,9 +231,9 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client, if (ret < 0) goto disable_clk; - ret = devm_request_threaded_irq(&client->dev, phy->i2c_dev->irq, NULL, - s3fwrn5_i2c_irq_thread_fn, IRQF_ONESHOT, - S3FWRN5_I2C_DRIVER_NAME, phy); + ret = request_threaded_irq(phy->i2c_dev->irq, + NULL, s3fwrn5_i2c_irq_thread_fn, + IRQF_ONESHOT, S3FWRN5_I2C_DRIVER_NAME, phy); if (ret) goto s3fwrn5_remove; @@ -250,6 +250,7 @@ static void s3fwrn5_i2c_remove(struct i2c_client *client) { struct s3fwrn5_i2c_phy *phy = i2c_get_clientdata(client); + free_irq(phy->i2c_dev->irq, phy); s3fwrn5_remove(phy->common.ndev); clk_disable_unprepare(phy->clk); } From patchwork Thu Sep 29 05:04:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12993495 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78F06C04A95 for ; Thu, 29 Sep 2022 05:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiI2FEj (ORCPT ); Thu, 29 Sep 2022 01:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234023AbiI2FEh (ORCPT ); Thu, 29 Sep 2022 01:04:37 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F3C2E2; Wed, 28 Sep 2022 22:04:32 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id g1-20020a17090a708100b00203c1c66ae3so303625pjk.2; Wed, 28 Sep 2022 22:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=BDWgwZsRIGEUohQLHcdxwjK+vB3fIpf3i8HDgHGiLrQ=; b=lOjKtTAyq/UW1zBmUa4fr/tMFAGL/1/VG0gzY9HFDvup77/S6sAonpS5IuIMZp8kI/ MJr0vfKkGlhVwolEb5Y2XQ/QnQKq5SHB6Vqx1j9JH8mRP3EjnOSBG4lpBJslsXmGRV55 1W/7RYapxb2ytju52OHXt+cZxbyphRiTU2qdqJWuAz+onvCmhBwcTPGbubc0uYYckCNL pI2okPbbOxTYqOiaoVopR3OY1sz/lL55Nak1Xms6wo3XnJWXW3kbBUnloc9MiFP7Vusa Cfxq8TdIZfIamRjhJtlMHkRfm1nzwzOSaP7SbCjjzoDOJeyfpxyNxvxb/fWJ4DNJO7cG kuZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=BDWgwZsRIGEUohQLHcdxwjK+vB3fIpf3i8HDgHGiLrQ=; b=IkwJnrSISM1d4DILoYb9zi8+BcZla4kypfLU8WoIcXMCKWt9RD+D88a3eoXRZnawnr ykBNiWKCv0Np2c+JFMeyhrb1Y5Iw1nzeSMSfyKYHXzLrzOFTF6FfmnatsXho/HwbF99H lVzzQczwWz4kyh9Hx9tWnFuaWCSPmtdBOwB0UwuqvIIwY6a6bVOepwztZBvZAxA+eofb OVeydDqGSHwaA5CIflrF3GNtDPvkRC4y9rDfhARwjBO7ZqRSkynnKhhDEuw8Gyfj7Ram Hs4AV2kuFyHGPdQcWYan/L3ccvhFknFt7NGo+Irq3HLxr28JXnM9O430qDwSX0p026x/ za0Q== X-Gm-Message-State: ACrzQf2MTONafzu1Pl4H/ImDNQYBcq2Wz8qkKQyEAwfVbl+ad+kO+lXn 5OmcD4kYXyaZguceMPP2NQxNIFc0LCg= X-Google-Smtp-Source: AMsMyM6B4mqozwKUMI+P1tqvfG6ToZ4fA1HMoeUcpQZIILgAWBcSRgDkGDRBL4lHUNcLICJ2PmBmqg== X-Received: by 2002:a17:90b:4c41:b0:202:78e9:472b with SMTP id np1-20020a17090b4c4100b0020278e9472bmr1675859pjb.207.1664427871470; Wed, 28 Sep 2022 22:04:31 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:637c:7f23:f348:a9e6]) by smtp.gmail.com with ESMTPSA id ij25-20020a170902ab5900b00179f370dbe7sm4314330plb.287.2022.09.28.22.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 22:04:30 -0700 (PDT) From: Dmitry Torokhov To: Krzysztof Kozlowski , Krzysztof Opasiak Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/2] nfc: s3fwrn5: use devm_clk_get_optional_enabled() helper Date: Wed, 28 Sep 2022 22:04:26 -0700 Message-Id: <20220929050426.955139-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929050426.955139-1-dmitry.torokhov@gmail.com> References: <20220929050426.955139-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Because we enable the clock immediately after acquiring it in probe, we can combine the 2 operations and use devm_clk_get_optional_enabled() helper. Signed-off-by: Dmitry Torokhov --- drivers/nfc/s3fwrn5/i2c.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c index fb36860df81c..2aaee2a8ff1c 100644 --- a/drivers/nfc/s3fwrn5/i2c.c +++ b/drivers/nfc/s3fwrn5/i2c.c @@ -209,22 +209,16 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client, if (ret < 0) return ret; - phy->clk = devm_clk_get_optional(&client->dev, NULL); - if (IS_ERR(phy->clk)) - return dev_err_probe(&client->dev, PTR_ERR(phy->clk), - "failed to get clock\n"); - /* * S3FWRN5 depends on a clock input ("XI" pin) to function properly. * Depending on the hardware configuration this could be an always-on * oscillator or some external clock that must be explicitly enabled. * Make sure the clock is running before starting S3FWRN5. */ - ret = clk_prepare_enable(phy->clk); - if (ret < 0) { - dev_err(&client->dev, "failed to enable clock: %d\n", ret); - return ret; - } + phy->clk = devm_clk_get_optional_enabled(&client->dev, NULL); + if (IS_ERR(phy->clk)) + return dev_err_probe(&client->dev, PTR_ERR(phy->clk), + "failed to get clock\n"); ret = s3fwrn5_probe(&phy->common.ndev, phy, &phy->i2c_dev->dev, &i2c_phy_ops);