This is a note to let you know that I've just added the patch titled media: v4l2-async: Don't use dynamic static allocation to the 3.12-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: media-v4l2-async-don-t-use-dynamic-static-allocation.patch and it can be found in the queue-3.12 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 24e9a47e14f0a97ee97abc3dd86b2ef254448a17 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab <m.chehab@xxxxxxxxxxx> Date: Sat, 2 Nov 2013 06:20:16 -0300 Subject: media: v4l2-async: Don't use dynamic static allocation From: Mauro Carvalho Chehab <m.chehab@xxxxxxxxxxx> commit 24e9a47e14f0a97ee97abc3dd86b2ef254448a17 upstream. Dynamic static allocation is evil, as Kernel stack is too low, and compilation complains about it on some archs: drivers/media/v4l2-core/v4l2-async.c:238:1: warning: 'v4l2_async_notifier_unregister' uses dynamic stack allocation [enabled by default] Instead, let's enforce a limit for the buffer. In this specific case, there's a hard limit imposed by V4L2_MAX_SUBDEVS, with is currently 128. That means that the buffer size can be up to 128x8 = 1024 bytes (on a 64bits kernel), with is too big for stack. Worse than that, someone could increase it and cause real troubles. So, let's use dynamically allocated data, instead. Signed-off-by: Mauro Carvalho Chehab <m.chehab@xxxxxxxxxxx> Reviewed-by: Hans Verkuil <hans.verkuil@xxxxxxxxx> Signed-off-by: Mauro Carvalho Chehab <m.chehab@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/media/v4l2-core/v4l2-async.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -189,30 +189,53 @@ void v4l2_async_notifier_unregister(stru struct v4l2_subdev *sd, *tmp; unsigned int notif_n_subdev = notifier->num_subdevs; unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS); - struct device *dev[n_subdev]; + struct device **dev; int i = 0; if (!notifier->v4l2_dev) return; + dev = kmalloc(n_subdev * sizeof(*dev), GFP_KERNEL); + if (!dev) { + dev_err(notifier->v4l2_dev->dev, + "Failed to allocate device cache!\n"); + } + mutex_lock(&list_lock); list_del(¬ifier->list); list_for_each_entry_safe(sd, tmp, ¬ifier->done, async_list) { - dev[i] = get_device(sd->dev); + struct device *d; + + d = get_device(sd->dev); v4l2_async_cleanup(sd); /* If we handled USB devices, we'd have to lock the parent too */ - device_release_driver(dev[i++]); + device_release_driver(d); if (notifier->unbind) notifier->unbind(notifier, sd, sd->asd); + + /* + * Store device at the device cache, in order to call + * put_device() on the final step + */ + if (dev) + dev[i++] = d; + else + put_device(d); } mutex_unlock(&list_lock); + /* + * Call device_attach() to reprobe devices + * + * NOTE: If dev allocation fails, i is 0, and the whole loop won't be + * executed. + */ while (i--) { struct device *d = dev[i]; @@ -228,6 +251,7 @@ void v4l2_async_notifier_unregister(stru } put_device(d); } + kfree(dev); notifier->v4l2_dev = NULL; Patches currently in stable-queue which might be from m.chehab@xxxxxxxxxxx are queue-3.12/media-af9015-don-t-use-dynamic-static-allocation.patch queue-3.12/media-dw2102-don-t-use-dynamic-static-allocation.patch queue-3.12/media-af9035-don-t-use-dynamic-static-allocation.patch queue-3.12/media-stb0899_drv-don-t-use-dynamic-static-allocation.patch queue-3.12/media-dibusb-common-don-t-use-dynamic-static-allocation.patch queue-3.12/media-cx18-struct-i2c_client-is-too-big-for-stack.patch queue-3.12/media-tuner-xc2028-don-t-use-dynamic-static-allocation.patch queue-3.12/media-cimax2-don-t-use-dynamic-static-allocation.patch queue-3.12/media-tuners-don-t-use-dynamic-static-allocation.patch queue-3.12/media-v4l2-async-don-t-use-dynamic-static-allocation.patch queue-3.12/media-dvb-frontends-again-don-t-use-dynamic-static-allocation.patch queue-3.12/media-dvb-frontends-don-t-use-dynamic-static-allocation.patch queue-3.12/media-stv090x-don-t-use-dynamic-static-allocation.patch queue-3.12/media-s5h1420-don-t-use-dynamic-static-allocation.patch queue-3.12/media-av7110_hw-don-t-use-dynamic-static-allocation.patch queue-3.12/media-stv0367-don-t-use-dynamic-static-allocation.patch queue-3.12/media-lirc_zilog-don-t-use-dynamic-static-allocation.patch queue-3.12/media-cxusb-don-t-use-dynamic-static-allocation.patch queue-3.12/media-mxl111sf-don-t-use-dynamic-static-allocation.patch -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html