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

Revert "media: qcom: camss: Restructure camss_link_entities"

This reverts commit cc1ecabe67d92a2da0b0402f715598e8dbdc3b9e.

This commit has a basic flaw in that it relies on camss->res->csid_num as a
control to index the array camss->vfe[i].

Testing on a platform where csid_num > vfe_num showed this bug up.

camss->vfe should only be indexed by camss->res->vfe_num. Since this commit
is meant to make the code be more readable reverting will simply restore
the previous correct bounds checking.

We can make another pass at making camss_link_entities look prettier but,
for now we should zap the bug introduced.

Fixes: cc1ecabe67d9 ("media: qcom: camss: Restructure camss_link_entities")
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>

authored by

Bryan O'Donoghue and committed by
Hans Verkuil
9229b53f 210afa15

+52 -103
+52 -103
drivers/media/platform/qcom/camss/camss.c
··· 2298 2298 } 2299 2299 2300 2300 /* 2301 + * camss_link_entities - Register subdev nodes and create links 2301 2302 * camss_link_err - print error in case link creation fails 2302 2303 * @src_name: name for source of the link 2303 2304 * @sink_name: name for sink of the link ··· 2316 2315 } 2317 2316 2318 2317 /* 2319 - * camss_link_entities_csid - Register subdev nodes and create links 2318 + * camss_link_entities - Register subdev nodes and create links 2320 2319 * @camss: CAMSS device 2321 2320 * 2322 2321 * Return 0 on success or a negative error code on failure 2323 2322 */ 2324 - static int camss_link_entities_csid(struct camss *camss) 2323 + static int camss_link_entities(struct camss *camss) 2325 2324 { 2326 - struct media_entity *src_entity; 2327 - struct media_entity *sink_entity; 2328 - int ret, line_num; 2329 - u16 sink_pad; 2330 - u16 src_pad; 2331 - int i, j; 2332 - 2333 - for (i = 0; i < camss->res->csid_num; i++) { 2334 - if (camss->ispif) 2335 - line_num = camss->ispif->line_num; 2336 - else 2337 - line_num = camss->vfe[i].res->line_num; 2338 - 2339 - src_entity = &camss->csid[i].subdev.entity; 2340 - for (j = 0; j < line_num; j++) { 2341 - if (camss->ispif) { 2342 - sink_entity = &camss->ispif->line[j].subdev.entity; 2343 - src_pad = MSM_CSID_PAD_SRC; 2344 - sink_pad = MSM_ISPIF_PAD_SINK; 2345 - } else { 2346 - sink_entity = &camss->vfe[i].line[j].subdev.entity; 2347 - src_pad = MSM_CSID_PAD_FIRST_SRC + j; 2348 - sink_pad = MSM_VFE_PAD_SINK; 2349 - } 2350 - 2351 - ret = media_create_pad_link(src_entity, 2352 - src_pad, 2353 - sink_entity, 2354 - sink_pad, 2355 - 0); 2356 - if (ret < 0) { 2357 - camss_link_err(camss, src_entity->name, 2358 - sink_entity->name, 2359 - ret); 2360 - return ret; 2361 - } 2362 - } 2363 - } 2364 - 2365 - return 0; 2366 - } 2367 - 2368 - /* 2369 - * camss_link_entities_csiphy - Register subdev nodes and create links 2370 - * @camss: CAMSS device 2371 - * 2372 - * Return 0 on success or a negative error code on failure 2373 - */ 2374 - static int camss_link_entities_csiphy(struct camss *camss) 2375 - { 2376 - int i, j; 2325 + int i, j, k; 2377 2326 int ret; 2378 2327 2379 2328 for (i = 0; i < camss->res->csiphy_num; i++) { ··· 2343 2392 } 2344 2393 } 2345 2394 2346 - return 0; 2347 - } 2348 - 2349 - /* 2350 - * camss_link_entities_ispif - Register subdev nodes and create links 2351 - * @camss: CAMSS device 2352 - * 2353 - * Return 0 on success or a negative error code on failure 2354 - */ 2355 - static int camss_link_entities_ispif(struct camss *camss) 2356 - { 2357 - int i, j, k; 2358 - int ret; 2359 - 2360 - for (i = 0; i < camss->ispif->line_num; i++) { 2361 - for (k = 0; k < camss->res->vfe_num; k++) { 2362 - for (j = 0; j < camss->vfe[k].res->line_num; j++) { 2363 - struct v4l2_subdev *ispif = &camss->ispif->line[i].subdev; 2364 - struct v4l2_subdev *vfe = &camss->vfe[k].line[j].subdev; 2365 - 2366 - ret = media_create_pad_link(&ispif->entity, 2367 - MSM_ISPIF_PAD_SRC, 2368 - &vfe->entity, 2369 - MSM_VFE_PAD_SINK, 2395 + if (camss->ispif) { 2396 + for (i = 0; i < camss->res->csid_num; i++) { 2397 + for (j = 0; j < camss->ispif->line_num; j++) { 2398 + ret = media_create_pad_link(&camss->csid[i].subdev.entity, 2399 + MSM_CSID_PAD_SRC, 2400 + &camss->ispif->line[j].subdev.entity, 2401 + MSM_ISPIF_PAD_SINK, 2370 2402 0); 2371 2403 if (ret < 0) { 2372 - camss_link_err(camss, ispif->entity.name, 2373 - vfe->entity.name, 2404 + camss_link_err(camss, 2405 + camss->csid[i].subdev.entity.name, 2406 + camss->ispif->line[j].subdev.entity.name, 2374 2407 ret); 2375 2408 return ret; 2376 2409 } 2377 2410 } 2378 2411 } 2412 + 2413 + for (i = 0; i < camss->ispif->line_num; i++) 2414 + for (k = 0; k < camss->res->vfe_num; k++) 2415 + for (j = 0; j < camss->vfe[k].res->line_num; j++) { 2416 + struct v4l2_subdev *ispif = &camss->ispif->line[i].subdev; 2417 + struct v4l2_subdev *vfe = &camss->vfe[k].line[j].subdev; 2418 + 2419 + ret = media_create_pad_link(&ispif->entity, 2420 + MSM_ISPIF_PAD_SRC, 2421 + &vfe->entity, 2422 + MSM_VFE_PAD_SINK, 2423 + 0); 2424 + if (ret < 0) { 2425 + camss_link_err(camss, ispif->entity.name, 2426 + vfe->entity.name, 2427 + ret); 2428 + return ret; 2429 + } 2430 + } 2431 + } else { 2432 + for (i = 0; i < camss->res->csid_num; i++) 2433 + for (k = 0; k < camss->res->vfe_num; k++) 2434 + for (j = 0; j < camss->vfe[k].res->line_num; j++) { 2435 + struct v4l2_subdev *csid = &camss->csid[i].subdev; 2436 + struct v4l2_subdev *vfe = &camss->vfe[k].line[j].subdev; 2437 + 2438 + ret = media_create_pad_link(&csid->entity, 2439 + MSM_CSID_PAD_FIRST_SRC + j, 2440 + &vfe->entity, 2441 + MSM_VFE_PAD_SINK, 2442 + 0); 2443 + if (ret < 0) { 2444 + camss_link_err(camss, csid->entity.name, 2445 + vfe->entity.name, 2446 + ret); 2447 + return ret; 2448 + } 2449 + } 2379 2450 } 2380 2451 2381 2452 return 0; 2382 - } 2383 - 2384 - /* 2385 - * camss_link_entities - Register subdev nodes and create links 2386 - * @camss: CAMSS device 2387 - * 2388 - * Return 0 on success or a negative error code on failure 2389 - */ 2390 - static int camss_link_entities(struct camss *camss) 2391 - { 2392 - int ret; 2393 - 2394 - ret = camss_link_entities_csiphy(camss); 2395 - if (ret < 0) 2396 - return ret; 2397 - 2398 - ret = camss_link_entities_csid(camss); 2399 - if (ret < 0) 2400 - return ret; 2401 - 2402 - if (camss->ispif) 2403 - ret = camss_link_entities_ispif(camss); 2404 - 2405 - return ret; 2406 2453 } 2407 2454 2408 2455 /*