mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-08-21 16:31:14 +02:00

Use devm_add_action_or_reset() to release resources in case of failure,
because the cleanup function will be automatically called.
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: He Lugang <helugang@uniontech.com>
Link: https://patchwork.freedesktop.org/patch/msgid/9631BC17D1E028A2+20240911102215.84865-1-helugang@uniontech.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
(cherry picked from commit fdc81c43f0
)
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
56 lines
1007 B
C
56 lines
1007 B
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2022 Intel Corporation
|
|
*/
|
|
|
|
#include "xe_gt_sysfs.h"
|
|
|
|
#include <linux/kobject.h>
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <drm/drm_managed.h>
|
|
|
|
#include "xe_gt.h"
|
|
|
|
static void xe_gt_sysfs_kobj_release(struct kobject *kobj)
|
|
{
|
|
kfree(kobj);
|
|
}
|
|
|
|
static const struct kobj_type xe_gt_sysfs_kobj_type = {
|
|
.release = xe_gt_sysfs_kobj_release,
|
|
.sysfs_ops = &kobj_sysfs_ops,
|
|
};
|
|
|
|
static void gt_sysfs_fini(void *arg)
|
|
{
|
|
struct xe_gt *gt = arg;
|
|
|
|
kobject_put(gt->sysfs);
|
|
}
|
|
|
|
int xe_gt_sysfs_init(struct xe_gt *gt)
|
|
{
|
|
struct xe_tile *tile = gt_to_tile(gt);
|
|
struct xe_device *xe = gt_to_xe(gt);
|
|
struct kobj_gt *kg;
|
|
int err;
|
|
|
|
kg = kzalloc(sizeof(*kg), GFP_KERNEL);
|
|
if (!kg)
|
|
return -ENOMEM;
|
|
|
|
kobject_init(&kg->base, &xe_gt_sysfs_kobj_type);
|
|
kg->gt = gt;
|
|
|
|
err = kobject_add(&kg->base, tile->sysfs, "gt%d", gt->info.id);
|
|
if (err) {
|
|
kobject_put(&kg->base);
|
|
return err;
|
|
}
|
|
|
|
gt->sysfs = &kg->base;
|
|
|
|
return devm_add_action_or_reset(xe->drm.dev, gt_sysfs_fini, gt);
|
|
}
|