Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: uvcvideo: Refactor iterators

Avoid using the iterators after the list_for_each() constructs.
This patch should be a NOP, but makes cocci, happier:

drivers/media/usb/uvc/uvc_ctrl.c:1861:44-50: ERROR: invalid reference to the index variable of the iterator on line 1850
drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to the index variable of the iterator on line 2179

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Ricardo Ribalda and committed by
Hans Verkuil
64627daf 2c7f7a3b

+13 -11
+13 -11
drivers/media/usb/uvc/uvc_ctrl.c
··· 1850 1850 list_for_each_entry(entity, &chain->entities, chain) { 1851 1851 ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback, 1852 1852 &err_ctrl); 1853 - if (ret < 0) 1853 + if (ret < 0) { 1854 + if (ctrls) 1855 + ctrls->error_idx = 1856 + uvc_ctrl_find_ctrl_idx(entity, ctrls, 1857 + err_ctrl); 1854 1858 goto done; 1859 + } 1855 1860 } 1856 1861 1857 1862 if (!rollback) 1858 1863 uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); 1859 1864 done: 1860 - if (ret < 0 && ctrls) 1861 - ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls, 1862 - err_ctrl); 1863 1865 mutex_unlock(&chain->ctrl_mutex); 1864 1866 return ret; 1865 1867 } ··· 2167 2165 int uvc_xu_ctrl_query(struct uvc_video_chain *chain, 2168 2166 struct uvc_xu_control_query *xqry) 2169 2167 { 2170 - struct uvc_entity *entity; 2168 + struct uvc_entity *entity, *iter; 2171 2169 struct uvc_control *ctrl; 2172 2170 unsigned int i; 2173 2171 bool found; ··· 2177 2175 int ret; 2178 2176 2179 2177 /* Find the extension unit. */ 2180 - found = false; 2181 - list_for_each_entry(entity, &chain->entities, chain) { 2182 - if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT && 2183 - entity->id == xqry->unit) { 2184 - found = true; 2178 + entity = NULL; 2179 + list_for_each_entry(iter, &chain->entities, chain) { 2180 + if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT && 2181 + iter->id == xqry->unit) { 2182 + entity = iter; 2185 2183 break; 2186 2184 } 2187 2185 } 2188 2186 2189 - if (!found) { 2187 + if (!entity) { 2190 2188 uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n", 2191 2189 xqry->unit); 2192 2190 return -ENOENT;