drm/i2c: tda998x: Remove VLA usage
Subsystems (2)
PATCH 1/1 drm/i2c: tda998x: Remove VLA usage
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The vla in reg_write_range is based on the length of data passed. The one use of a non-constant size for this range is bounded by the size buffer passed to hdmi_infoframe_pack which is a fixed size. Switch to this upper bound.
[1] https://lkml.org/lkml/2018/3/7/621
---
This one really feels like it should be a #define but I wasn't sure where the 32 came from. It looks like most other uses use one of the #defines in include/linux/hdmi?
--- drivers/gpu/drm/i2c/tda998x_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i2c/tda998x_drv.c +2 -1
@@ -470,7 +470,8 @@ static void reg_write_range(struct tda998x_priv *priv, u16 reg, u8 *p, int cnt) { struct i2c_client *client = priv->hdmi; -u8 buf[cnt+1 ]; +/* This is the maximum size of the buffer passed in */ +u8 buf[33 ];int ret; buf[0 ] =REG2ADDR (reg);
Signature · 1 line
2.14.3
Quoted 5 lines · Laura Abbott
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The vla in
reg_write_rangeis based on the length of data passed. The one use of a non-constant size for this range is bounded by the size buffer passed tohdmi_infoframe_packwhich is a fixed size. Switch to this upper bound.
Does this _really_ make it safer? What if the code is modified to write more than 32 bytes in the future?
Sorry, I don't think this is safer at all.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
Quoted 7 lines · Russell King - ARM Linux
Quoted 5 lines · Laura Abbott
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The vla in
reg_write_rangeis based on the length of data passed. The one use of a non-constant size for this range is bounded by the size buffer passed tohdmi_infoframe_packwhich is a fixed size. Switch to this upper bound.
Quoted 5 lines
Does this _really_ make it safer? What if the code is modified to write more than 32 bytes in the future?
Sorry, I don't think this is safer at all.
Yeah I wasn't 100% sure about this one. Elsewhere, we've added bounds checks against the new static size buffer so we could do that here to ensure we don't overrun the stack if we do need to write more than 32 bytes in the future. Another option is to switch to a kmalloc buffer. Are either of those options acceptable to you or do you have a better idea of how to get rid of the VLA?
Thanks,
Laura
Quoted 14 lines · Laura Abbott
Quoted 7 lines · Russell King - ARM Linux
Quoted 5 lines · Laura Abbott
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The vla in
reg_write_rangeis based on the length of data passed. The one use of a non-constant size for this range is bounded by the size buffer passed tohdmi_infoframe_packwhich is a fixed size. Switch to this upper bound.Quoted 5 lines
Does this _really_ make it safer? What if the code is modified to write more than 32 bytes in the future?
Sorry, I don't think this is safer at all.
Quoted 6 lines
Yeah I wasn't 100% sure about this one. Elsewhere, we've added bounds checks against the new static size buffer so we could do that here to ensure we don't overrun the stack if we do need to write more than 32 bytes in the future. Another option is to switch to a kmalloc buffer. Are either of those options acceptable to you or do you have a better idea of how to get rid of the VLA?
Limiting the size would be better (with an error message/WARN_ON) - at least that results in a diagnostic message to alert the developer rather than silently stomping over the stack.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up