Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1633826 > unrolled thread

[PATCH v3 1/2] mwifiex: initiate card-specific work atomically

Started byBrian Norris <briannorris@chromium.org>
First post2017-05-01 21:40 +0200
Last post2017-05-01 21:40 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3 1/2] mwifiex: initiate card-specific work atomically Brian Norris <briannorris@chromium.org> - 2017-05-01 21:40 +0200
    Re: [PATCH v3 1/2] mwifiex: initiate card-specific work atomically Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-05-01 21:40 +0200

#1633826 — [PATCH v3 1/2] mwifiex: initiate card-specific work atomically

FromBrian Norris <briannorris@chromium.org>
Date2017-05-01 21:40 +0200
Subject[PATCH v3 1/2] mwifiex: initiate card-specific work atomically
Message-ID<tCpkR-4KF-5@gated-at.bofh.it>
The non-atomic test + set is a little awkward here, and it technically
means we might double-schedule work unnecessarily. AFAICT, this is not
really a problem, since the extra "work" will be a no-op (the flag(s)
will be cleared by then), but it's still an anti-pattern.

Rewrite this to use the atomic test_and_set_bit() helper instead.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---
v3: fix bisectability (unused code warning) -- some code from patch 2
    crept in here

v2: new
---
 drivers/net/wireless/marvell/mwifiex/pcie.c |  9 +++------
 drivers/net/wireless/marvell/mwifiex/sdio.c | 16 +++++-----------
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
index ac62bce50e96..5f56e8e6d612 100644
--- a/drivers/net/wireless/marvell/mwifiex/pcie.c
+++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
@@ -2837,12 +2837,9 @@ static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter)
 {
 	struct pcie_service_card *card = adapter->card;
 
-	if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags))
-		return;
-
-	set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags);
-
-	schedule_work(&card->work);
+	if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
+			      &card->work_flags))
+		schedule_work(&card->work);
 }
 
 static void mwifiex_pcie_free_buffers(struct mwifiex_adapter *adapter)
diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c
index 0af1c6733c92..d38d31bb9b79 100644
--- a/drivers/net/wireless/marvell/mwifiex/sdio.c
+++ b/drivers/net/wireless/marvell/mwifiex/sdio.c
@@ -2533,12 +2533,8 @@ static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter)
 {
 	struct sdio_mmc_card *card = adapter->card;
 
-	if (test_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags))
-		return;
-
-	set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags);
-
-	schedule_work(&card->work);
+	if (!test_and_set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags))
+		schedule_work(&card->work);
 }
 
 /* This function dumps FW information */
@@ -2546,11 +2542,9 @@ static void mwifiex_sdio_device_dump(struct mwifiex_adapter *adapter)
 {
 	struct sdio_mmc_card *card = adapter->card;
 
-	if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags))
-		return;
-
-	set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags);
-	schedule_work(&card->work);
+	if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
+			      &card->work_flags))
+		schedule_work(&card->work);
 }
 
 /* Function to dump SDIO function registers and SDIO scratch registers in case
-- 
2.13.0.rc0.306.g87b477812d-goog

[toc] | [next] | [standalone]


#1633827

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-05-01 21:40 +0200
Message-ID<tCpkR-4KF-13@gated-at.bofh.it>
In reply to#1633826
On Mon, May 01, 2017 at 12:36:59PM -0700, Brian Norris wrote:
> The non-atomic test + set is a little awkward here, and it technically
> means we might double-schedule work unnecessarily. AFAICT, this is not
> really a problem, since the extra "work" will be a no-op (the flag(s)
> will be cleared by then), but it's still an anti-pattern.
> 
> Rewrite this to use the atomic test_and_set_bit() helper instead.
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

> ---
> v3: fix bisectability (unused code warning) -- some code from patch 2
>     crept in here
> 
> v2: new
> ---
>  drivers/net/wireless/marvell/mwifiex/pcie.c |  9 +++------
>  drivers/net/wireless/marvell/mwifiex/sdio.c | 16 +++++-----------
>  2 files changed, 8 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
> index ac62bce50e96..5f56e8e6d612 100644
> --- a/drivers/net/wireless/marvell/mwifiex/pcie.c
> +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
> @@ -2837,12 +2837,9 @@ static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter)
>  {
>  	struct pcie_service_card *card = adapter->card;
>  
> -	if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags))
> -		return;
> -
> -	set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags);
> -
> -	schedule_work(&card->work);
> +	if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
> +			      &card->work_flags))
> +		schedule_work(&card->work);
>  }
>  
>  static void mwifiex_pcie_free_buffers(struct mwifiex_adapter *adapter)
> diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c
> index 0af1c6733c92..d38d31bb9b79 100644
> --- a/drivers/net/wireless/marvell/mwifiex/sdio.c
> +++ b/drivers/net/wireless/marvell/mwifiex/sdio.c
> @@ -2533,12 +2533,8 @@ static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter)
>  {
>  	struct sdio_mmc_card *card = adapter->card;
>  
> -	if (test_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags))
> -		return;
> -
> -	set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags);
> -
> -	schedule_work(&card->work);
> +	if (!test_and_set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags))
> +		schedule_work(&card->work);
>  }
>  
>  /* This function dumps FW information */
> @@ -2546,11 +2542,9 @@ static void mwifiex_sdio_device_dump(struct mwifiex_adapter *adapter)
>  {
>  	struct sdio_mmc_card *card = adapter->card;
>  
> -	if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags))
> -		return;
> -
> -	set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags);
> -	schedule_work(&card->work);
> +	if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
> +			      &card->work_flags))
> +		schedule_work(&card->work);
>  }
>  
>  /* Function to dump SDIO function registers and SDIO scratch registers in case
> -- 
> 2.13.0.rc0.306.g87b477812d-goog
> 

-- 
Dmitry

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web