Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/syncobj: __free() variables not initialized at declaration site --
commit d2db4e35813dabf4fb7e2f45ff5acb392b0b03ac Author: Tvrtko Ursulin <[email protected]> drm/syncobj: Use scoped cleanup in drm_syncobj_array_find and callers This commit converts drm_syncobj_array_find() and its ioctl callers to use scoped cleanup (__free) and moves the syncobj array allocation and maximum handle count checks into the callers. > diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c > index da90ae11382e3..6b4df322b12a8 100644 > --- a/drivers/gpu/drm/drm_syncobj.c > +++ b/drivers/gpu/drm/drm_syncobj.c > @@ -1252,59 +1252,38 @@ static int drm_syncobj_array_wait(struct drm_device > *dev, > return 0; > } > > -static int drm_syncobj_array_find(struct drm_file *file_private, > - void __user *user_handles, > - uint32_t count_handles, > - struct drm_syncobj ***syncobjs_out) > -{ > - uint32_t i, *handles; > +struct syncobj_array { > struct drm_syncobj **syncobjs; > - int ret; > + unsigned int count; > +}; > > - if (count_handles > DRM_SYNCOBJ_MAX_HANDLES) > - return -EINVAL; > +static void syncobj_array_free(struct syncobj_array *a) > +{ > + for (unsigned int i = 0; i < a->count; i++) > + drm_syncobj_put(a->syncobjs[i]); > +} > > - handles = vmemdup_array_user(user_handles, count_handles, > - sizeof(*handles)); > - if (IS_ERR(handles)) > - return PTR_ERR(handles); > +DEFINE_FREE(syncobj_array, struct syncobj_array, syncobj_array_free(&_T)) > > - syncobjs = kvmalloc_objs(*syncobjs, count_handles); > - if (syncobjs == NULL) { > - ret = -ENOMEM; > - goto err_free_handles; > - } > +static int drm_syncobj_array_find(struct drm_file *file_private, > + void __user *user_handles, unsigned int count, > + struct syncobj_array *array) > +{ > + u32 *handles __free(kvfree) = NULL; > + unsigned int i; > > - for (i = 0; i < count_handles; i++) { > - syncobjs[i] = drm_syncobj_find(file_private, handles[i]); > - if (!syncobjs[i]) { > - ret = -ENOENT; > - goto err_put_syncobjs; > - } > + handles = vmemdup_array_user(user_handles, count, sizeof(*handles)); [ ... ] > @@ -1312,10 +1291,11 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void > *data, > struct drm_file *file_private) > { > struct drm_syncobj_wait *args = data; > - struct drm_syncobj **syncobjs; > + struct drm_syncobj **syncobjs __free(kvfree) = NULL; > + struct syncobj_array array __free(syncobj_array) = {}; > unsigned int possible_flags; > ktime_t t, *tp = NULL; > - int ret = 0; > + int ret; > > if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) > return -EOPNOTSUPP; > @@ -1329,11 +1309,17 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void > *data, > > if (args->count_handles == 0) > return 0; > + else if (args->count_handles > DRM_SYNCOBJ_MAX_HANDLES) > + return -EINVAL; > + > + syncobjs = kvmalloc_objs(*syncobjs, args->count_handles); > + if (!syncobjs) > + return -ENOMEM; > > + array.syncobjs = syncobjs; [Severity: Low] This isn't a bug, but cleanup.h recommends defining and initializing __free() variables in a single statement at their allocation site rather than declaring them with = NULL at the top of the function and assigning them later. Doing that for handles in drm_syncobj_array_find() and for syncobjs (and array) in drm_syncobj_wait_ioctl() and the other five ioctl callers in this patch also ensures reverse-acquisition cleanup order naturally without relying on manual declaration ordering at the top of each function. -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
