ov5648: Don't pack controls struct
Subsystems (2)
Sakari Ailus
maintainerPATCH 1/1 ov5648: Don't pack controls struct
Don't pack the driver specific struct containing control pointers. This lead to potential alignment issues when working with the pointers.
--- drivers/media/i2c/ov5648.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov5648.c +1 -1
@@ -639,7 +639,7 @@ struct ov5648_ctrls {struct v4l2_ctrl *pixel_rate;struct v4l2_ctrl_handler handler; -} __packed; +};struct ov5648_sensor {struct device *dev;
Signature · 1 line
2.30.2
Hi Sakari,
Quoted 2 lines · Sakari Ailus
Don't pack the driver specific struct containing control pointers. This lead to potential alignment issues when working with the pointers.
Thanks for looking into the report and making this fix.
Honestly I was a bit puzzled because I explicitly added the __packed to avoid possible holes in the structures that could be problematic when using v4l2_ctrl_auto_cluster and I think the problem still stands.
I feel like solving both issues at once would require having the controls that belong in the same cluster declared as an array and not individual members of the struct.
What do you think?
Cheers,
Paul
Quoted 23 lines
Reported-by kernel test robot <[email protected]>Fixes e43ccb0a045f ("media: i2c: Add support for the OV5648 image sensor")Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ov5648.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov5648.c +1
-1@@ -639,7 +639,7 @@ struct ov5648_ctrls {struct v4l2_ctrl *pixel_rate;struct v4l2_ctrl_handler handler; -} __packed; +};struct ov5648_sensor {struct device *dev;Signature · 1 line
2.30.2
Signature · 3 lines
Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Sakari Ailus
maintainerHi Paul,
Quoted 12 lines · Paul Kocialkowski
Hi Sakari,
Quoted 2 lines · Sakari Ailus
Don't pack the driver specific struct containing control pointers. This lead to potential alignment issues when working with the pointers.
Thanks for looking into the report and making this fix.
Honestly I was a bit puzzled because I explicitly added the
__packedto avoid possible holes in the structures that could be problematic when usingv4l2_ctrl_auto_clusterand I think the problem still stands.
Quoted 5 lines
I feel like solving both issues at once would require having the controls that belong in the same cluster declared as an array and not individual members of the struct.
What do you think?
No architecture used in Linux requires adding padding between two pointers to my knowledge --- generally the alignment is at most the size of the
data: otherwise arrays would not work either. Therefore packing isn't required.
Signature · 3 lines
Kind regards, Sakari Ailus
Hi Sakari,
Quoted 19 lines · Sakari Ailus
Hi Paul,
Quoted 16 lines · Paul Kocialkowski
Hi Sakari,
Quoted 2 lines · Sakari Ailus
Don't pack the driver specific struct containing control pointers. This lead to potential alignment issues when working with the pointers.
Thanks for looking into the report and making this fix.
Honestly I was a bit puzzled because I explicitly added the
__packedto avoid possible holes in the structures that could be problematic when usingv4l2_ctrl_auto_clusterand I think the problem still stands.I feel like solving both issues at once would require having the controls that belong in the same cluster declared as an array and not individual members of the struct.
Quoted 6 lines
Quoted 1 line
What do you think?
No architecture used in Linux requires adding padding between two pointers to my knowledge --- generally the alignment is at most the size of the
data: otherwise arrays would not work either. Therefore packing isn't required.
I was under the impression that padding may happen in structures generally speaking. Are you saying that because it's pointers, there will most likely be no padding required?
Also there's a struct v4l2_ctrl_handler at the end of the struct (not a pointer), maybe that can somehow play a role too and introduce padding?
My feeling was that there's no strong guarantee here, so packing the struct would be the safe thing to do. I also don't see how unaligned access can occur in the packed struct in that case (pointers should always offset to something properly aligned, shouldn't they?).
Paul
Signature · 3 lines
Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Sakari Ailus
maintainerHi Paul,
Quoted 24 lines · Paul Kocialkowski
Hi Sakari,
Quoted 21 lines · Sakari Ailus
Hi Paul,
Quoted 17 lines · Paul Kocialkowski
Hi Sakari,
Quoted 2 lines · Sakari Ailus
Don't pack the driver specific struct containing control pointers. This lead to potential alignment issues when working with the pointers.
Thanks for looking into the report and making this fix.
Honestly I was a bit puzzled because I explicitly added the
__packedto avoid possible holes in the structures that could be problematic when usingv4l2_ctrl_auto_clusterand I think the problem still stands.I feel like solving both issues at once would require having the controls that belong in the same cluster declared as an array and not individual members of the struct.
What do you think?
Quoted 8 lines
Quoted 4 lines
No architecture used in Linux requires adding padding between two pointers to my knowledge --- generally the alignment is at most the size of the
data: otherwise arrays would not work either. Therefore packing isn't required.I was under the impression that padding may happen in structures generally speaking. Are you saying that because it's pointers, there will most likely be no padding required?
Not really just pointers; the same goes for any data type.
Quoted 3 lines
Also there's a struct
v4l2_ctrl_handlerat the end of the struct (not a pointer), maybe that can somehow play a role too and introduce padding?
There could be padding added at the end of the struct. (But that depends on what comes after the struct.)
Quoted 5 lines
My feeling was that there's no strong guarantee here, so packing the struct would be the safe thing to do. I also don't see how unaligned access can occur in the packed struct in that case (pointers should always offset to something properly aligned, shouldn't they?).
My understanding is this is a false positive warning from clang. Gcc does not complain but I'm not sure it's capable of doing that either.
Of course it would be the best to fix clang but until that happens or we change the code, we'll be permanent targets of these e-mails.
Still __packed isn't needed here.
Signature · 3 lines
Kind regards, Sakari Ailus
Paul Kocialkowski
Reviewed-byHi Sakari,
Quoted 51 lines · Sakari Ailus
Hi Paul,
Quoted 24 lines · Paul Kocialkowski
Hi Sakari,
Quoted 21 lines · Sakari Ailus
Hi Paul,
Quoted 17 lines · Paul Kocialkowski
Hi Sakari,
Quoted 2 lines · Sakari Ailus
Don't pack the driver specific struct containing control pointers. This lead to potential alignment issues when working with the pointers.
Thanks for looking into the report and making this fix.
Honestly I was a bit puzzled because I explicitly added the
__packedto avoid possible holes in the structures that could be problematic when usingv4l2_ctrl_auto_clusterand I think the problem still stands.I feel like solving both issues at once would require having the controls that belong in the same cluster declared as an array and not individual members of the struct.
What do you think?
Quoted 8 lines
Quoted 4 lines
No architecture used in Linux requires adding padding between two pointers to my knowledge --- generally the alignment is at most the size of the
data: otherwise arrays would not work either. Therefore packing isn't required.I was under the impression that padding may happen in structures generally speaking. Are you saying that because it's pointers, there will most likely be no padding required?
Not really just pointers; the same goes for any data type.
Quoted 3 lines
Also there's a struct
v4l2_ctrl_handlerat the end of the struct (not a pointer), maybe that can somehow play a role too and introduce padding?There could be padding added at the end of the struct. (But that depends on what comes after the struct.)
Quoted 5 lines
My feeling was that there's no strong guarantee here, so packing the struct would be the safe thing to do. I also don't see how unaligned access can occur in the packed struct in that case (pointers should always offset to something properly aligned, shouldn't they?).
Quoted 7 lines
My understanding is this is a false positive warning from clang. Gcc does not complain but I'm not sure it's capable of doing that either.
Of course it would be the best to fix clang but until that happens or we change the code, we'll be permanent targets of these e-mails.
Still
__packedisn't needed here.
Okay understood, thanks!
So all in all I was under the impression that padding can be added by the compiler "as it likes" but it seems that it will only happen for alignment reasons. However here no padding should be required between pointers to maintain alignment, so we're good. Is that correct?
If that's right then feel free to add:
Thanks,
Paul
Signature · 3 lines
Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com