lkml.org 
[lkml]   [2025]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC 08/14] vfio/nvgrace-egm: Expose EGM region as char device
On Thu, Sep 04, 2025 at 04:08:22AM +0000, ankita@nvidia.com wrote:
> +static struct chardev *
> +setup_egm_chardev(struct nvgrace_egm_dev *egm_dev)
> +{
> + struct chardev *egm_chardev;
> + int ret;
> +
> + egm_chardev = kvzalloc(sizeof(*egm_chardev), GFP_KERNEL);
> + if (!egm_chardev)
> + goto create_err;
> +
> + device_initialize(&egm_chardev->device);
> +
> + /*
> + * Use the proximity domain number as the device minor
> + * number. So the EGM corresponding to node X would be
> + * /dev/egmX.
> + */
> + egm_chardev->device.devt = MKDEV(MAJOR(dev), egm_dev->egmpxm);
> + egm_chardev->device.class = class;
> + egm_chardev->device.release = egm_chardev_release;
> + egm_chardev->device.parent = &egm_dev->aux_dev.dev;
> + cdev_init(&egm_chardev->cdev, &file_ops);
> + egm_chardev->cdev.owner = THIS_MODULE;
> +
> + ret = dev_set_name(&egm_chardev->device, "egm%lld", egm_dev->egmpxm);
> + if (ret)
> + goto error_exit;
> +
> + ret = cdev_device_add(&egm_chardev->cdev, &egm_chardev->device);
> + if (ret)
> + goto error_exit;
> +
> + return egm_chardev;
> +
> +error_exit:
> + kvfree(egm_chardev);

After calling init you have to use put_device not kvfree.

Why kvalloc anyhow? Struct chardev is not big

> static void egm_driver_remove(struct auxiliary_device *aux_dev)
> {
> + struct nvgrace_egm_dev *egm_dev =
> + container_of(aux_dev, struct nvgrace_egm_dev, aux_dev);
> + struct chardev *egm_chardev = xa_erase(&egm_chardevs, egm_dev->egmpxm);
> +
> + if (!egm_chardev)
> + return;
> +
> + del_egm_chardev(egm_chardev);
> }

This proceeds even if files are left open which is not going to be any
good..

Jason

\
 
 \ /
  Last update: 2025-09-05 15:37    [from the cache]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog