Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/imagination: missing pvr_fw_object_vunmap() on pvr_fw_process() error path --
commit 77938768831abdc044ee8cfa1b2e3bb5e025c962 Author: Matt Coster <[email protected]> drm/imagination: Generalize FW segment loading This commit replaces the per-segment firmware loading code and fields in struct pvr_fw_mem with a segment descriptor table and an array of struct pvr_fw_segment entries. > diff --git a/drivers/gpu/drm/imagination/pvr_fw.c > b/drivers/gpu/drm/imagination/pvr_fw.c > index 4e082f83cff02..fbd46231f5803 100644 > --- a/drivers/gpu/drm/imagination/pvr_fw.c > +++ b/drivers/gpu/drm/imagination/pvr_fw.c [ ... ] > @@ -462,6 +426,76 @@ pvr_fw_destroy_structures(struct pvr_device *pvr_dev) [ ... ] > +static void > +pvr_fw_destroy_segments(struct pvr_fw_segment segments[static > PVR_FW_SEGMENT_COUNT]) > +{ > + for (int i = PVR_FW_SEGMENT_COUNT - 1; i >= 0; i--) { > + struct pvr_fw_segment *segment = &segments[i]; > + > + if (segment->obj) > + pvr_fw_object_destroy(segment->obj); > + segment->obj = NULL; > + > + kfree(segment->host_copy); > + segment->host_copy = NULL; > + } > +} [ ... ] > @@ -492,142 +526,58 @@ pvr_fw_process(struct pvr_device *pvr_dev, const > struct firmware *firmware) > return -EINVAL; > > /* Allocate and map memory for firmware sections. */ > + for (int seg = 0; seg < PVR_FW_SEGMENT_COUNT; seg++) { > + const struct pvr_fw_segment_desc *desc = > &pvr_fw_segment_descs[seg]; > + struct pvr_fw_segment *segment = &fw_mem->segments[seg]; > + void *host_ptr; > + > + if (!segment->size) { > + if (desc->required) { > + drm_err(drm_dev, "Required FW segment '%s' is > empty\n", desc->name); > + err = -EINVAL; > + goto err_out; > + } > > + continue; > + } > > + segment->host_copy = kzalloc(segment->size, GFP_KERNEL); > + if (!segment->host_copy) { > + err = -ENOMEM; > + goto err_out; > + } > > + host_ptr = desc->create_and_map(pvr_dev, segment, > private_data->base_addr); > + if (IS_ERR(host_ptr)) { > + drm_err(drm_dev, "Failed to allocate FW memory for > segment '%s'\n", > + desc->name); > + err = PTR_ERR(host_ptr); > + goto err_out; > + } > > + host_ptrs[seg] = host_ptr; > } > > + err = pvr_dev->fw_dev.defs->fw_process(pvr_dev, firmware, > fw_mem->segments); > if (err) > + goto err_out; > + > + for (int seg = 0; seg < PVR_FW_SEGMENT_COUNT; seg++) { > + const struct pvr_fw_segment *segment = &fw_mem->segments[seg]; > + > + if (!segment->obj) > + continue; > + > + memcpy(host_ptrs[seg], segment->host_copy, segment->size); > + > + host_ptrs[seg] = NULL; > + pvr_fw_object_vunmap(segment->obj); > } > > return 0; > > +err_out: > + pvr_fw_destroy_segments(fw_mem->segments); > > return err; > } [Severity: Medium] Does the err_out path in pvr_fw_process() miss calling pvr_fw_object_vunmap() on segments that were already mapped by desc->create_and_map()? If a later segment allocation or defs->fw_process() fails, pvr_fw_destroy_segments() destroys each segment->obj while its CPU mapping in host_ptrs[seg] is still active. Unlike the pre-patch cleanup path, which called pvr_fw_object_vunmap() before pvr_fw_object_destroy(), destroying the still-mapped GEM shmem object triggers drm_WARN_ON() in drm_gem_shmem_release() and leaks the vmap mapping and pinned backing pages. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/20261125-b4-commonize-fw-segment-loading-v1-0-69657fa52...@imgtec.com?part=5
