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

Configure Feed

Select the types of activity you want to include in your feed.

drm/v3d: Consolidate CPU job validation in a function

All CPU job extension parsers duplicate the same validation procedure:
ensure the extension is attached to a CPU job (not a GPU job) and that
only a single CPU job extension is associated with a given job.

Create a function to consolidate these checks and reduce the boilerplate
across the various CPU job extension handlers. While here, convert the
legacy DRM_DEBUG with a more appropriate drm_dbg().

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Link: https://patch.msgid.link/20260112-v3d-drm-debug-v2-1-8ef6244c97bb@igalia.com
Signed-off-by: Maíra Canal <mcanal@igalia.com>

+26 -48
+26 -48
drivers/gpu/drm/v3d/v3d_submit.c
··· 404 404 return 0; 405 405 } 406 406 407 + /* Returns false if the CPU job has an invalid configuration. */ 408 + static bool 409 + v3d_validate_cpu_job(struct drm_file *file_priv, struct v3d_cpu_job *job) 410 + { 411 + struct v3d_file_priv *v3d_priv = file_priv->driver_priv; 412 + struct v3d_dev *v3d = v3d_priv->v3d; 413 + 414 + if (!job) { 415 + drm_dbg(&v3d->drm, "CPU job extension was attached to a GPU job.\n"); 416 + return false; 417 + } 418 + 419 + if (job->job_type) { 420 + drm_dbg(&v3d->drm, "Two CPU job extensions were added to the same CPU job.\n"); 421 + return false; 422 + } 423 + 424 + return true; 425 + } 426 + 407 427 /* Get data for the indirect CSD job submission. */ 408 428 static int 409 429 v3d_get_cpu_indirect_csd_params(struct drm_file *file_priv, ··· 435 415 struct drm_v3d_indirect_csd indirect_csd; 436 416 struct v3d_indirect_csd_info *info = &job->indirect_csd; 437 417 438 - if (!job) { 439 - DRM_DEBUG("CPU job extension was attached to a GPU job.\n"); 418 + if (!v3d_validate_cpu_job(file_priv, job)) 440 419 return -EINVAL; 441 - } 442 - 443 - if (job->job_type) { 444 - DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n"); 445 - return -EINVAL; 446 - } 447 420 448 421 if (copy_from_user(&indirect_csd, ext, sizeof(indirect_csd))) 449 422 return -EFAULT; ··· 471 458 unsigned int i; 472 459 int err; 473 460 474 - if (!job) { 475 - DRM_DEBUG("CPU job extension was attached to a GPU job.\n"); 461 + if (!v3d_validate_cpu_job(file_priv, job)) 476 462 return -EINVAL; 477 - } 478 - 479 - if (job->job_type) { 480 - DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n"); 481 - return -EINVAL; 482 - } 483 463 484 464 if (copy_from_user(&timestamp, ext, sizeof(timestamp))) 485 465 return -EFAULT; ··· 533 527 unsigned int i; 534 528 int err; 535 529 536 - if (!job) { 537 - DRM_DEBUG("CPU job extension was attached to a GPU job.\n"); 530 + if (!v3d_validate_cpu_job(file_priv, job)) 538 531 return -EINVAL; 539 - } 540 - 541 - if (job->job_type) { 542 - DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n"); 543 - return -EINVAL; 544 - } 545 532 546 533 if (copy_from_user(&reset, ext, sizeof(reset))) 547 534 return -EFAULT; ··· 587 588 unsigned int i; 588 589 int err; 589 590 590 - if (!job) { 591 - DRM_DEBUG("CPU job extension was attached to a GPU job.\n"); 591 + if (!v3d_validate_cpu_job(file_priv, job)) 592 592 return -EINVAL; 593 - } 594 - 595 - if (job->job_type) { 596 - DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n"); 597 - return -EINVAL; 598 - } 599 593 600 594 if (copy_from_user(&copy, ext, sizeof(copy))) 601 595 return -EFAULT; ··· 716 724 struct drm_v3d_reset_performance_query reset; 717 725 int err; 718 726 719 - if (!job) { 720 - DRM_DEBUG("CPU job extension was attached to a GPU job.\n"); 727 + if (!v3d_validate_cpu_job(file_priv, job)) 721 728 return -EINVAL; 722 - } 723 - 724 - if (job->job_type) { 725 - DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n"); 726 - return -EINVAL; 727 - } 728 729 729 730 if (copy_from_user(&reset, ext, sizeof(reset))) 730 731 return -EFAULT; ··· 755 770 struct drm_v3d_copy_performance_query copy; 756 771 int err; 757 772 758 - if (!job) { 759 - DRM_DEBUG("CPU job extension was attached to a GPU job.\n"); 773 + if (!v3d_validate_cpu_job(file_priv, job)) 760 774 return -EINVAL; 761 - } 762 - 763 - if (job->job_type) { 764 - DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n"); 765 - return -EINVAL; 766 - } 767 775 768 776 if (copy_from_user(&copy, ext, sizeof(copy))) 769 777 return -EFAULT;