2022-03-02 21:00:11

by Christian Lamparter

[permalink] [raw]
Subject: [PATCH v1 1/5] carl9170: replace GFP_ATOMIC in ampdu_action, it can sleep

Since ~2010, the driver is allowed to sleep in the ampdu_action
callback thanks to:
commit 85ad181ea788 ("mac80211: allow drivers to sleep in ampdu_action")

Signed-off-by: Christian Lamparter <[email protected]>
---
drivers/net/wireless/ath/carl9170/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
index 2208ec800482..f6974aff0c59 100644
--- a/drivers/net/wireless/ath/carl9170/main.c
+++ b/drivers/net/wireless/ath/carl9170/main.c
@@ -1412,7 +1412,7 @@ static int carl9170_op_ampdu_action(struct ieee80211_hw *hw,
return -EOPNOTSUPP;

tid_info = kzalloc(sizeof(struct carl9170_sta_tid),
- GFP_ATOMIC);
+ GFP_KERNEL);
if (!tid_info)
return -ENOMEM;

--
2.35.1


2022-03-02 22:05:26

by Christian Lamparter

[permalink] [raw]
Subject: [PATCH v1 2/5] carl9170: devres-ing hwrng_register usage

devres will take care of freeing the hwrng once it is no longer needed.

Signed-off-by: Christian Lamparter <[email protected]>
---
drivers/net/wireless/ath/carl9170/carl9170.h | 1 -
drivers/net/wireless/ath/carl9170/main.c | 29 ++------------------
2 files changed, 3 insertions(+), 27 deletions(-)

diff --git a/drivers/net/wireless/ath/carl9170/carl9170.h b/drivers/net/wireless/ath/carl9170/carl9170.h
index 84a8ce0784b1..ba29b4aebe9f 100644
--- a/drivers/net/wireless/ath/carl9170/carl9170.h
+++ b/drivers/net/wireless/ath/carl9170/carl9170.h
@@ -458,7 +458,6 @@ struct ar9170 {
# define CARL9170_HWRNG_CACHE_SIZE CARL9170_MAX_CMD_PAYLOAD_LEN
struct {
struct hwrng rng;
- bool initialized;
char name[30 + 1];
u16 cache[CARL9170_HWRNG_CACHE_SIZE / sizeof(u16)];
unsigned int cache_idx;
diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
index f6974aff0c59..9495b3da1978 100644
--- a/drivers/net/wireless/ath/carl9170/main.c
+++ b/drivers/net/wireless/ath/carl9170/main.c
@@ -1539,7 +1539,7 @@ static int carl9170_rng_get(struct ar9170 *ar)

BUILD_BUG_ON(RB > CARL9170_MAX_CMD_PAYLOAD_LEN);

- if (!IS_ACCEPTING_CMD(ar) || !ar->rng.initialized)
+ if (!IS_ACCEPTING_CMD(ar))
return -EAGAIN;

count = ARRAY_SIZE(ar->rng.cache);
@@ -1585,14 +1585,6 @@ static int carl9170_rng_read(struct hwrng *rng, u32 *data)
return sizeof(u16);
}

-static void carl9170_unregister_hwrng(struct ar9170 *ar)
-{
- if (ar->rng.initialized) {
- hwrng_unregister(&ar->rng.rng);
- ar->rng.initialized = false;
- }
-}
-
static int carl9170_register_hwrng(struct ar9170 *ar)
{
int err;
@@ -1603,25 +1595,14 @@ static int carl9170_register_hwrng(struct ar9170 *ar)
ar->rng.rng.data_read = carl9170_rng_read;
ar->rng.rng.priv = (unsigned long)ar;

- if (WARN_ON(ar->rng.initialized))
- return -EALREADY;
-
- err = hwrng_register(&ar->rng.rng);
+ err = devm_hwrng_register(&ar->udev->dev, &ar->rng.rng);
if (err) {
dev_err(&ar->udev->dev, "Failed to register the random "
"number generator (%d)\n", err);
return err;
}

- ar->rng.initialized = true;
-
- err = carl9170_rng_get(ar);
- if (err) {
- carl9170_unregister_hwrng(ar);
- return err;
- }
-
- return 0;
+ return carl9170_rng_get(ar);
}
#endif /* CONFIG_CARL9170_HWRNG */

@@ -2064,10 +2045,6 @@ void carl9170_unregister(struct ar9170 *ar)
}
#endif /* CONFIG_CARL9170_WPC */

-#ifdef CONFIG_CARL9170_HWRNG
- carl9170_unregister_hwrng(ar);
-#endif /* CONFIG_CARL9170_HWRNG */
-
carl9170_cancel_worker(ar);
cancel_work_sync(&ar->restart_work);

--
2.35.1

2022-03-02 23:37:15

by Christian Lamparter

[permalink] [raw]
Subject: [PATCH v1 3/5] carl9170: devres-ing input_allocate_device

devres will take care of freeing the input_device once
it is no longer needed.

Signed-off-by: Christian Lamparter <[email protected]>
---
drivers/net/wireless/ath/carl9170/main.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
index 9495b3da1978..e833052e9056 100644
--- a/drivers/net/wireless/ath/carl9170/main.c
+++ b/drivers/net/wireless/ath/carl9170/main.c
@@ -1494,7 +1494,7 @@ static int carl9170_register_wps_button(struct ar9170 *ar)
if (!(ar->features & CARL9170_WPS_BUTTON))
return 0;

- input = input_allocate_device();
+ input = devm_input_allocate_device(&ar->udev->dev);
if (!input)
return -ENOMEM;

@@ -1512,10 +1512,8 @@ static int carl9170_register_wps_button(struct ar9170 *ar)
input_set_capability(input, EV_KEY, KEY_WPS_BUTTON);

err = input_register_device(input);
- if (err) {
- input_free_device(input);
+ if (err)
return err;
- }

ar->wps.pbc = input;
return 0;
@@ -2038,13 +2036,6 @@ void carl9170_unregister(struct ar9170 *ar)
carl9170_debugfs_unregister(ar);
#endif /* CONFIG_CARL9170_DEBUGFS */

-#ifdef CONFIG_CARL9170_WPC
- if (ar->wps.pbc) {
- input_unregister_device(ar->wps.pbc);
- ar->wps.pbc = NULL;
- }
-#endif /* CONFIG_CARL9170_WPC */
-
carl9170_cancel_worker(ar);
cancel_work_sync(&ar->restart_work);

--
2.35.1

2022-03-03 00:31:34

by Christian Lamparter

[permalink] [raw]
Subject: [PATCH v1 4/5] carl9170: replace bitmap_zalloc with devm_bitmap_zalloc

the mem_bitmap is kept around for the lifetime of the
driver device. This is a perfect candidate for devm.

Signed-off-by: Christian Lamparter <[email protected]>
---
drivers/net/wireless/ath/carl9170/main.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
index e833052e9056..fae927ca4863 100644
--- a/drivers/net/wireless/ath/carl9170/main.c
+++ b/drivers/net/wireless/ath/carl9170/main.c
@@ -1943,11 +1943,7 @@ int carl9170_register(struct ar9170 *ar)
struct ath_regulatory *regulatory = &ar->common.regulatory;
int err = 0, i;

- if (WARN_ON(ar->mem_bitmap))
- return -EINVAL;
-
- ar->mem_bitmap = bitmap_zalloc(ar->fw.mem_blocks, GFP_KERNEL);
-
+ ar->mem_bitmap = devm_bitmap_zalloc(&ar->udev->dev, ar->fw.mem_blocks, GFP_KERNEL);
if (!ar->mem_bitmap)
return -ENOMEM;

@@ -2050,9 +2046,6 @@ void carl9170_free(struct ar9170 *ar)
kfree_skb(ar->rx_failover);
ar->rx_failover = NULL;

- bitmap_free(ar->mem_bitmap);
- ar->mem_bitmap = NULL;
-
kfree(ar->survey);
ar->survey = NULL;

--
2.35.1

2022-03-11 00:56:19

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v1 1/5] carl9170: replace GFP_ATOMIC in ampdu_action, it can sleep

Christian Lamparter <[email protected]> wrote:

> Since ~2010, the driver is allowed to sleep in the ampdu_action
> callback thanks to:
> commit 85ad181ea788 ("mac80211: allow drivers to sleep in ampdu_action")
>
> Signed-off-by: Christian Lamparter <[email protected]>
> Signed-off-by: Kalle Valo <[email protected]>

5 patches applied to ath-next branch of ath.git, thanks.

e42fe43a216c carl9170: replace GFP_ATOMIC in ampdu_action, it can sleep
23de0fa0d2a0 carl9170: devres-ing hwrng_register usage
87ddb2fc29f1 carl9170: devres-ing input_allocate_device
a8da65f901fa carl9170: replace bitmap_zalloc with devm_bitmap_zalloc
83fe43abdacf carl9170: devres ar->survey_info

--
https://patchwork.kernel.org/project/linux-wireless/patch/0036538d0933626a1a5eb2c2c3935cf173028926.1646250537.git.chunkeey@gmail.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches