lkml.org 
[lkml]   [2024]   [Feb]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH V4 2/5] misc: mlx5ctl: Add mlx5ctl misc driver
From

On 07/02/2024 08:24, Saeed Mahameed wrote:
> +static int mlx5ctl_open(struct inode *inode, struct file *file)
> +{
> + struct mlx5_core_dev *mdev;
> + struct mlx5ctl_dev *mcdev;
> + struct mlx5ctl_fd *mfd;
> + int err = 0;
> +
> + mcdev = container_of(file->private_data, struct mlx5ctl_dev, miscdev);
> + mcdev_get(mcdev);
> + down_read(&mcdev->rw_lock);
> + mdev = mcdev->mdev;
> + if (!mdev) {
> + err = -ENODEV;
> + goto unlock;
> + }
> +
> + mfd = kzalloc(sizeof(*mfd), GFP_KERNEL_ACCOUNT);
> + if (!mfd)
> + return -ENOMEM;

goto unlock?

Or why not reorder so you always allocate this before doing anything else?

> +
> + mfd->mcdev = mcdev;
> + err = mlx5ctl_open_mfd(mfd);
> + if (err)
> + goto unlock;
> +
> + spin_lock(&mcdev->fd_list_lock);
> + list_add_tail(&mfd->list, &mcdev->fd_list);
> + spin_unlock(&mcdev->fd_list_lock);
> +
> + file->private_data = mfd;
> +
> +unlock:
> + up_read(&mcdev->rw_lock);
> + if (err) {
> + mcdev_put(mcdev);
> + kfree(mfd);
> + }
> + return err;
> +}


Vegard

\
 
 \ /
  Last update: 2024-05-27 15:28    [W:0.262 / U:0.576 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site