staging/wlan-ng query: convert to flexible array member
Hello,
First, my apologies for the long email.
I am requesting guidance on how to approach resolving the zero element flexible VLO struct implementation in this driver in file drivers/staging/waln-ng/hfa384x.f
The struct hfa384x_pdrec contains nested structs with zero element arrays. These zero element structs are part of a union 'data' inside the struct container. This union 'data' is the last element of this container. Please see the code snip below:
<snip>
1068 struct hfa384x_pdrec {
1 __le16 len; /* in words */
2 __le16 code;
3 union pdr {
4 struct hfa384x_pdr_pcb_partnum pcb_partnum;
11 struct hfa384x_pdr_nicid nicid;
12 struct hfa384x_pdr_refdac_measurements refdac_measurements;
13 struct hfa384x_pdr_vgdac_measurements vgdac_measurements;
14 struct hfa384x_pdr_level_comp_measurements level_compc_measurements;
15 struct hfa384x_pdr_mac_address mac_address;
39 } data;
40 } __packed;</snip>
The three structures in question are declared as follows in the same file:
<snip>
962 struct hfa384x_pdr_refdac_measurements {
1 u16 value[0];
2 } __packed;
3
4 struct hfa384x_pdr_vgdac_measurements {
5 u16 value[0];
6 } __packed;
7
8 struct hfa384x_pdr_level_comp_measurements {
9 u16 value[0];
10 } __packed;</snip>
As per the C99 specifications, the flexible array struct should have at least one member other than the true flexible array member. So converting these from
[0] to [] is not feasible in the current form.
I did not find these struct variables being used for memory allocation in the code directly. My find may be short since the implementation appears to get very complex as I tried to get deeper.
Can you please suggest how should I approach correcting the zero element flex array implementation here? Can these structs be removed if they are unused?
Thank you.
./drv
Greg Kroah-Hartman
maintainerQuoted 47 lines · Deepak R Varma
Hello,
First, my apologies for the long email.
I am requesting guidance on how to approach resolving the zero element flexible VLO struct implementation in this driver in filedrivers/staging/waln-ng/hfa384x.fThe struct
hfa384x_pdreccontains nested structs with zero element arrays. These zero element structs are part of a union 'data' inside the struct container. This union 'data' is the last element of this container. Please see the code snip below:<snip>
1068 struct hfa384x_pdrec { 1 __le16 len; /* in words */ 2 __le16 code; 3 union pdr { 4 struct hfa384x_pdr_pcb_partnum pcb_partnum; 11 struct hfa384x_pdr_nicid nicid; 12 struct hfa384x_pdr_refdac_measurements refdac_measurements; 13 struct hfa384x_pdr_vgdac_measurements vgdac_measurements; 14 struct hfa384x_pdr_level_comp_measurements level_compc_measurements; 15 struct hfa384x_pdr_mac_address mac_address; 39 } data; 40 } __packed;</snip>
The three structures in question are declared as follows in the same file:
<snip>
962 struct hfa384x_pdr_refdac_measurements { 1 u16 value[0]; 2 } __packed; 3 4 struct hfa384x_pdr_vgdac_measurements { 5 u16 value[0]; 6 } __packed; 7 8 struct hfa384x_pdr_level_comp_measurements { 9 u16 value[0]; 10 } __packed;</snip>
As per the C99 specifications, the flexible array struct should have at least one member other than the true flexible array member. So converting these from
[0] to [] is not feasible in the current form.
Quoted 6 lines
I did not find these struct variables being used for memory allocation in the code directly. My find may be short since the implementation appears to get very complex as I tried to get deeper.
Can you please suggest how should I approach correcting the zero element flex array implementation here? Can these structs be removed if they are unused?
Are you sure they are unused?
They look like structures that are read from the memory of a device, right? Try removing the structures from the union and see what happens :)
thanks,
greg k-h
Quoted 52 lines · Greg Kroah-Hartman
Quoted 51 lines · Deepak R Varma
Hello,
First, my apologies for the long email.
I am requesting guidance on how to approach resolving the zero element flexible VLO struct implementation in this driver in filedrivers/staging/waln-ng/hfa384x.fThe struct
hfa384x_pdreccontains nested structs with zero element arrays. These zero element structs are part of a union 'data' inside the struct container. This union 'data' is the last element of this container. Please see the code snip below:<snip>
1068 struct hfa384x_pdrec { 1 __le16 len; /* in words */ 2 __le16 code; 3 union pdr { 4 struct hfa384x_pdr_pcb_partnum pcb_partnum; 11 struct hfa384x_pdr_nicid nicid; 12 struct hfa384x_pdr_refdac_measurements refdac_measurements; 13 struct hfa384x_pdr_vgdac_measurements vgdac_measurements; 14 struct hfa384x_pdr_level_comp_measurements level_compc_measurements; 15 struct hfa384x_pdr_mac_address mac_address; 39 } data; 40 } __packed;</snip>
The three structures in question are declared as follows in the same file:
<snip>
962 struct hfa384x_pdr_refdac_measurements { 1 u16 value[0]; 2 } __packed; 3 4 struct hfa384x_pdr_vgdac_measurements { 5 u16 value[0]; 6 } __packed; 7 8 struct hfa384x_pdr_level_comp_measurements { 9 u16 value[0]; 10 } __packed;</snip>
As per the C99 specifications, the flexible array struct should have at least one member other than the true flexible array member. So converting these from
[0] to [] is not feasible in the current form.I did not find these struct variables being used for memory allocation in the code directly. My find may be short since the implementation appears to get very complex as I tried to get deeper.
Quoted 8 lines
Quoted 2 lines
Can you please suggest how should I approach correcting the zero element flex array implementation here? Can these structs be removed if they are unused?
Are you sure they are unused?
They look like structures that are read from the memory of a device, right? Try removing the structures from the union and see what happens :)
I did remove the structs from the union and it built fine. Is there anything else I can check/test to verify the impact?
<snip>
drv@qemulion:~/git/kernels/staging$ git diff
diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h
index 0611e37df6ac..8fe10aa93dfb 100644
--- a/drivers/staging/wlan-ng/hfa384x.h
+++ b/drivers/staging/wlan-ng/hfa384x.h
@@ -1077,9 +1077,6 @@ struct hfa384x_pdrec {
struct hfa384x_pdr_mfisuprange mfisuprange;
struct hfa384x_pdr_cfisuprange cfisuprange;
struct hfa384x_pdr_nicid nicid;
- struct hfa384x_pdr_refdac_measurements refdac_measurements;
- struct hfa384x_pdr_vgdac_measurements vgdac_measurements;
- struct hfa384x_pdr_level_comp_measurements level_compc_measurements;
struct hfa384x_pdr_mac_address mac_address;
struct hfa384x_pdr_mkk_callname mkk_callname;
struct hfa384x_pdr_regdomain regdomain;
drv@qemulion:~/git/kernels/staging$ make M=drivers/staging/wlan-ng/
CC [M] drivers/staging/wlan-ng/prism2usb.o
CC [M] drivers/staging/wlan-ng/p80211netdev.o
LD [M] drivers/staging/wlan-ng/prism2_usb.o
MODPOST drivers/staging/wlan-ng/Module.symvers
LD [M] drivers/staging/wlan-ng/prism2_usb.ko
BTF [M] drivers/staging/wlan-ng/prism2_usb.ko
drv@qemulion:~/git/kernels/staging$
</snip>Quoted 4 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 82 lines · Deepak R Varma
Quoted 52 lines · Greg Kroah-Hartman
Quoted 51 lines · Deepak R Varma
Hello,
First, my apologies for the long email.
I am requesting guidance on how to approach resolving the zero element flexible VLO struct implementation in this driver in filedrivers/staging/waln-ng/hfa384x.fThe struct
hfa384x_pdreccontains nested structs with zero element arrays. These zero element structs are part of a union 'data' inside the struct container. This union 'data' is the last element of this container. Please see the code snip below:<snip>
1068 struct hfa384x_pdrec { 1 __le16 len; /* in words */ 2 __le16 code; 3 union pdr { 4 struct hfa384x_pdr_pcb_partnum pcb_partnum; 11 struct hfa384x_pdr_nicid nicid; 12 struct hfa384x_pdr_refdac_measurements refdac_measurements; 13 struct hfa384x_pdr_vgdac_measurements vgdac_measurements; 14 struct hfa384x_pdr_level_comp_measurements level_compc_measurements; 15 struct hfa384x_pdr_mac_address mac_address; 39 } data; 40 } __packed;</snip>
The three structures in question are declared as follows in the same file:
<snip>
962 struct hfa384x_pdr_refdac_measurements { 1 u16 value[0]; 2 } __packed; 3 4 struct hfa384x_pdr_vgdac_measurements { 5 u16 value[0]; 6 } __packed; 7 8 struct hfa384x_pdr_level_comp_measurements { 9 u16 value[0]; 10 } __packed;</snip>
As per the C99 specifications, the flexible array struct should have at least one member other than the true flexible array member. So converting these from
[0] to [] is not feasible in the current form.I did not find these struct variables being used for memory allocation in the code directly. My find may be short since the implementation appears to get very complex as I tried to get deeper.
Quoted 8 lines
Quoted 2 lines
Can you please suggest how should I approach correcting the zero element flex array implementation here? Can these structs be removed if they are unused?
Are you sure they are unused?
They look like structures that are read from the memory of a device, right? Try removing the structures from the union and see what happens :)
I did remove the structs from the union and it built fine. Is there anything else I can check/test to verify the impact?
<snip>
drv@qemulion:~/git/kernels/staging$ git diff diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h index 0611e37df6ac..8fe10aa93dfb 100644 --- a/drivers/staging/wlan-ng/hfa384x.h +++ b/drivers/staging/wlan-ng/hfa384x.h @@ -1077,9 +1077,6 @@ struct hfa384x_pdrec { struct hfa384x_pdr_mfisuprange mfisuprange; struct hfa384x_pdr_cfisuprange cfisuprange; struct hfa384x_pdr_nicid nicid; - struct hfa384x_pdr_refdac_measurements refdac_measurements; - struct hfa384x_pdr_vgdac_measurements vgdac_measurements; - struct hfa384x_pdr_level_comp_measurements level_compc_measurements; struct hfa384x_pdr_mac_address mac_address; struct hfa384x_pdr_mkk_callname mkk_callname; struct hfa384x_pdr_regdomain regdomain; drv@qemulion:~/git/kernels/staging$ make M=drivers/staging/wlan-ng/
Quoted 9 lines
CC [M] drivers/staging/wlan-ng/prism2usb.o CC [M] drivers/staging/wlan-ng/p80211netdev.o LD [M] drivers/staging/wlan-ng/prism2_usb.o MODPOST drivers/staging/wlan-ng/Module.symvers LD [M] drivers/staging/wlan-ng/prism2_usb.ko BTF [M] drivers/staging/wlan-ng/prism2_usb.ko drv@qemulion:~/git/kernels/staging$ </snip>
Test the device to make sure it still works?
Quoted 10 lines · Greg Kroah-Hartman
Quoted 7 lines · Deepak R Varma
On Tue, Nov 08, 2022 at 04:34:15PM +0100, Greg Kroah-Hartman wrote:
MODPOSTdrivers/staging/wlan-ng/Module.symversLD [M]drivers/staging/wlan-ng/prism2_usb.koBTF [M]drivers/staging/wlan-ng/prism2_usb.ko
drv@qemulion:~/git/kernels/staging$
</snip>Test the device to make sure it still works?
I was able to build and load the driver on my machine. I do not have p54 device to test. Is there another way to test it? Some sort of a udev program???
<snip>
static struct usb_driver prism2_usb_driver = {
- .name = "prism2_usb",
+ .name = "prism2_usb_dvk",
.probe = prism2sta_probe_usb,
.disconnect = prism2sta_disconnect_usb,
.id_table = usb_prism_tbl,
drv@qemulion:~/git/kernels/staging$ sudo dmesg
[ 948.476144] prism2_usb: module is from the staging directory, the quality is unknown, you have been warned. [ 948.478631] usbcore: registered new interface driver prism2_usb_dvk
</snip>
Thank you,
./drv
Quoted 1 line
Greg Kroah-Hartman
maintainerQuoted 10 lines · Deepak R Varma
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Deepak R Varma
On Tue, Nov 08, 2022 at 04:34:15PM +0100, Greg Kroah-Hartman wrote:
MODPOSTdrivers/staging/wlan-ng/Module.symversLD [M]drivers/staging/wlan-ng/prism2_usb.koBTF [M]drivers/staging/wlan-ng/prism2_usb.ko
drv@qemulion:~/git/kernels/staging$
</snip>
Quoted 4 lines
Quoted 1 line
Test the device to make sure it still works?
I was able to build and load the driver on my machine. I do not have p54 device to test. Is there another way to test it? Some sort of a udev program???
You need the real hardware to test it properly.
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Deepak R Varma
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Deepak R Varma
On Tue, Nov 08, 2022 at 04:34:15PM +0100, Greg Kroah-Hartman wrote:
MODPOSTdrivers/staging/wlan-ng/Module.symversLD [M]drivers/staging/wlan-ng/prism2_usb.koBTF [M]drivers/staging/wlan-ng/prism2_usb.ko
drv@qemulion:~/git/kernels/staging$
</snip>
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Test the device to make sure it still works?
I was able to build and load the driver on my machine. I do not have p54 device to test. Is there another way to test it? Some sort of a udev program???
You need the real hardware to test it properly.
Do you know if I work with someone to test the change locally rather than sending in a untested change?
Thank you,
./drv
Quoted 1 line
Greg Kroah-Hartman
maintainerQuoted 14 lines · Deepak R Varma
Quoted 13 lines · Greg Kroah-Hartman
Quoted 12 lines · Deepak R Varma
Quoted 10 lines · Greg Kroah-Hartman
Quoted 7 lines · Deepak R Varma
On Tue, Nov 08, 2022 at 04:34:15PM +0100, Greg Kroah-Hartman wrote:
MODPOSTdrivers/staging/wlan-ng/Module.symversLD [M]drivers/staging/wlan-ng/prism2_usb.koBTF [M]drivers/staging/wlan-ng/prism2_usb.ko
drv@qemulion:~/git/kernels/staging$
</snip>Test the device to make sure it still works?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I was able to build and load the driver on my machine. I do not have p54 device to test. Is there another way to test it? Some sort of a udev program???
You need the real hardware to test it properly.
Do you know if I work with someone to test the change locally rather than sending in a untested change?
If you can find someone, sure!
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Deepak R Varma
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines
Quoted 1 line
Test the device to make sure it still works?
I was able to build and load the driver on my machine. I do not have p54 device to test. Is there another way to test it? Some sort of a udev program???
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
You need the real hardware to test it properly.
Do you know if I work with someone to test the change locally rather than sending in a untested change?
If you can find someone, sure!
Hello Greg,
I reached out to couple of recent patch authors to check if they are able to help test the change.
Hello all,
Does anyone have a hardware that can test prism2_usb [wlan-ng] driver change? I assume it would be quick to test the change I am proposing. Let me know if you are able to help.
Thank you!
./drv
Quoted 1 line
Quoted 3 lines · Deepak R Varma
Can you please suggest how should I approach correcting the zero element flex array implementation here? Can these structs be removed if they are unused?
You can try using DECLARE_FLEX_ARRAY(). See this[1] patch.
--
Gustavo
[1] https://git.kernel.org/linus/6e4a53ee7989c8a2b9fc3b14cd90f6e2d613ca76
Quoted 6 lines · Gustavo A. R. Silva
Quoted 3 lines · Deepak R Varma
Can you please suggest how should I approach correcting the zero element flex array implementation here? Can these structs be removed if they are unused?
You can try using
DECLARE_FLEX_ARRAY(). See this[1] patch.
Thank you very much for the quick reply. The link you provided is very helpful. I will review it in detail and correct my patch proposal accordingly.
ps: Also. thank you for including the cc list. I has already made a lot of noise with on the lists, so did not copy them intentionally in my email to you.
./drv
Quoted 6 lines
--
Gustavo[1] https://git.kernel.org/linus/6e4a53ee7989c8a2b9fc3b14cd90f6e2d613ca76