Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH wireless-next] wifi: rt2x00: allocate anchor with rt2x00dev
@ 2026-04-30 23:22 Rosen Penev
  2026-05-09 10:13 ` Stanislaw Gruszka
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-04-30 23:22 UTC (permalink / raw)
  To: linux-wireless; +Cc: Stanislaw Gruszka, open list

Instead of being creative with devm, allocate with rt2x00dev by using a
flexible array member. Simplifies code slightly.

It's worth noting that in 25369b22223d1c56e42a0cd4ac9137349d5a898e , the
proper device was set to the devm call as it seems there was confusion
there.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2x00.h    |  3 ++-
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 11 +----------
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
index 665887e9b118..7d313e86d3f2 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
@@ -1009,11 +1009,12 @@ struct rt2x00_dev {
 	/* Extra TX headroom required for alignment purposes. */
 	unsigned int extra_tx_headroom;

-	struct usb_anchor *anchor;
 	unsigned int num_proto_errs;

 	/* Clock for System On Chip devices. */
 	struct clk *clk;
+
+	struct usb_anchor anchor[];
 };

 struct rt2x00_bar_list_entry {
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
index 174d89b0b1d7..47e427ea8622 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
@@ -804,7 +804,7 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,

 	usb_reset_device(usb_dev);

-	hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
+	hw = ieee80211_alloc_hw(struct_size(rt2x00dev, anchor, 1), ops->hw);
 	if (!hw) {
 		rt2x00_probe_err("Failed to allocate hardware\n");
 		return -ENOMEM;
@@ -826,13 +826,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
 	if (retval)
 		goto exit_free_device;

-	rt2x00dev->anchor = devm_kmalloc(&usb_intf->dev,
-					sizeof(struct usb_anchor),
-					GFP_KERNEL);
-	if (!rt2x00dev->anchor) {
-		retval = -ENOMEM;
-		goto exit_free_reg;
-	}
 	init_usb_anchor(rt2x00dev->anchor);

 	retval = rt2x00lib_probe_dev(rt2x00dev);
@@ -843,8 +836,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,

 exit_free_anchor:
 	usb_kill_anchored_urbs(rt2x00dev->anchor);
-
-exit_free_reg:
 	rt2x00usb_free_reg(rt2x00dev);

 exit_free_device:
--
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH wireless-next] wifi: rt2x00: allocate anchor with rt2x00dev
  2026-04-30 23:22 [PATCH wireless-next] wifi: rt2x00: allocate anchor with rt2x00dev Rosen Penev
@ 2026-05-09 10:13 ` Stanislaw Gruszka
  2026-05-09 21:18   ` Rosen Penev
  0 siblings, 1 reply; 3+ messages in thread
From: Stanislaw Gruszka @ 2026-05-09 10:13 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-wireless, open list

Hi,

On Thu, Apr 30, 2026 at 04:22:06PM -0700, Rosen Penev wrote:
> Instead of being creative with devm, allocate with rt2x00dev by using a
> flexible array member. Simplifies code slightly.

I think this patch is more creative. Using a flexible array member
is less conventional than the current approach of allocating separately
and storing a pointer. But OK, lets get rid of 9 LOC.

Acked-by: Stanislaw Gruszka <stf_xl@wp.pl>

> It's worth noting that in 25369b22223d1c56e42a0cd4ac9137349d5a898e , the
> proper device was set to the devm call as it seems there was confusion
> there.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>
> ---
>  drivers/net/wireless/ralink/rt2x00/rt2x00.h    |  3 ++-
>  drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 11 +----------
>  2 files changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
> index 665887e9b118..7d313e86d3f2 100644
> --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
> +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
> @@ -1009,11 +1009,12 @@ struct rt2x00_dev {
>  	/* Extra TX headroom required for alignment purposes. */
>  	unsigned int extra_tx_headroom;
> 
> -	struct usb_anchor *anchor;
>  	unsigned int num_proto_errs;
> 
>  	/* Clock for System On Chip devices. */
>  	struct clk *clk;
> +
> +	struct usb_anchor anchor[];
>  };
> 
>  struct rt2x00_bar_list_entry {
> diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> index 174d89b0b1d7..47e427ea8622 100644
> --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> @@ -804,7 +804,7 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
> 
>  	usb_reset_device(usb_dev);
> 
> -	hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
> +	hw = ieee80211_alloc_hw(struct_size(rt2x00dev, anchor, 1), ops->hw);
>  	if (!hw) {
>  		rt2x00_probe_err("Failed to allocate hardware\n");
>  		return -ENOMEM;
> @@ -826,13 +826,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
>  	if (retval)
>  		goto exit_free_device;
> 
> -	rt2x00dev->anchor = devm_kmalloc(&usb_intf->dev,
> -					sizeof(struct usb_anchor),
> -					GFP_KERNEL);
> -	if (!rt2x00dev->anchor) {
> -		retval = -ENOMEM;
> -		goto exit_free_reg;
> -	}
>  	init_usb_anchor(rt2x00dev->anchor);
> 
>  	retval = rt2x00lib_probe_dev(rt2x00dev);
> @@ -843,8 +836,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
> 
>  exit_free_anchor:
>  	usb_kill_anchored_urbs(rt2x00dev->anchor);
> -
> -exit_free_reg:
>  	rt2x00usb_free_reg(rt2x00dev);
> 
>  exit_free_device:
> --
> 2.54.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH wireless-next] wifi: rt2x00: allocate anchor with rt2x00dev
  2026-05-09 10:13 ` Stanislaw Gruszka
@ 2026-05-09 21:18   ` Rosen Penev
  0 siblings, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2026-05-09 21:18 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: linux-wireless, open list

On Sat, May 9, 2026 at 3:13 AM Stanislaw Gruszka <stf_xl@wp.pl> wrote:
>
> Hi,
>
> On Thu, Apr 30, 2026 at 04:22:06PM -0700, Rosen Penev wrote:
> > Instead of being creative with devm, allocate with rt2x00dev by using a
> > flexible array member. Simplifies code slightly.
>
> I think this patch is more creative. Using a flexible array member
> is less conventional than the current approach of allocating separately
> and storing a pointer. But OK, lets get rid of 9 LOC.
I don't see how a FAM is more creative. It's a single allocation. It
also takes up less struct space as the pointer gets removed. The other
usage of ieee80211_alloc_hw and struct_size is in ath12k:

drivers/net/wireless/ath/ath12k/mac.c: hw =
ieee80211_alloc_hw(struct_size(ah, radio, num_pdev_map),

Actually there are more but instead of struct_size they use manual addition.
>
> Acked-by: Stanislaw Gruszka <stf_xl@wp.pl>
>
> > It's worth noting that in 25369b22223d1c56e42a0cd4ac9137349d5a898e , the
> > proper device was set to the devm call as it seems there was confusion
> > there.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> >
> > ---
> >  drivers/net/wireless/ralink/rt2x00/rt2x00.h    |  3 ++-
> >  drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 11 +----------
> >  2 files changed, 3 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
> > index 665887e9b118..7d313e86d3f2 100644
> > --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
> > +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
> > @@ -1009,11 +1009,12 @@ struct rt2x00_dev {
> >       /* Extra TX headroom required for alignment purposes. */
> >       unsigned int extra_tx_headroom;
> >
> > -     struct usb_anchor *anchor;
> >       unsigned int num_proto_errs;
> >
> >       /* Clock for System On Chip devices. */
> >       struct clk *clk;
> > +
> > +     struct usb_anchor anchor[];
> >  };
> >
> >  struct rt2x00_bar_list_entry {
> > diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> > index 174d89b0b1d7..47e427ea8622 100644
> > --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> > +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> > @@ -804,7 +804,7 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
> >
> >       usb_reset_device(usb_dev);
> >
> > -     hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
> > +     hw = ieee80211_alloc_hw(struct_size(rt2x00dev, anchor, 1), ops->hw);
> >       if (!hw) {
> >               rt2x00_probe_err("Failed to allocate hardware\n");
> >               return -ENOMEM;
> > @@ -826,13 +826,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
> >       if (retval)
> >               goto exit_free_device;
> >
> > -     rt2x00dev->anchor = devm_kmalloc(&usb_intf->dev,
> > -                                     sizeof(struct usb_anchor),
> > -                                     GFP_KERNEL);
> > -     if (!rt2x00dev->anchor) {
> > -             retval = -ENOMEM;
> > -             goto exit_free_reg;
> > -     }
> >       init_usb_anchor(rt2x00dev->anchor);
> >
> >       retval = rt2x00lib_probe_dev(rt2x00dev);
> > @@ -843,8 +836,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
> >
> >  exit_free_anchor:
> >       usb_kill_anchored_urbs(rt2x00dev->anchor);
> > -
> > -exit_free_reg:
> >       rt2x00usb_free_reg(rt2x00dev);
> >
> >  exit_free_device:
> > --
> > 2.54.0
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-09 21:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 23:22 [PATCH wireless-next] wifi: rt2x00: allocate anchor with rt2x00dev Rosen Penev
2026-05-09 10:13 ` Stanislaw Gruszka
2026-05-09 21:18   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox