Re: [RFC_v2 1/4] HID: hid-sony: Add basic IIO support for SixAxis Controller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<snip>

>> +static const struct iio_info sony_iio_info = {
>> +     .read_raw = &sony_iio_read_raw,
>> +     .driver_module = THIS_MODULE,
>> +};
>> +
>> +static int sony_iio_probe(struct sony_sc *sc)
>> +{
>> +     struct hid_device *hdev = sc->hdev;
>> +     struct iio_dev *indio_dev;
>> +     struct sony_iio *data;
>> +     int ret;
>> +
>> +     indio_dev = iio_device_alloc(sizeof(*data));
>
> In general for new code the devm_ variants are preferred, but I am
> not sure in this case, maybe others have comments about that?
>
>> +     if (!indio_dev)
>> +             return -ENOMEM;
>> +
>> +     sc->indio_dev = indio_dev;
>> +     data = iio_priv(indio_dev);
>> +     data->sc = sc;
>> +
>> +     indio_dev->dev.parent = &hdev->dev;
>> +     indio_dev->name = dev_name(&hdev->dev);
>> +     indio_dev->modes = INDIO_DIRECT_MODE;
>> +     indio_dev->info = &sony_iio_info;
>> +     indio_dev->channels = sony_sixaxis_channels;
>> +     indio_dev->num_channels = 3;

Use ARRAY_SIZE(sony_sixaxis_channels) here.

>> +
>> +     ret = iio_device_register(indio_dev);
>
> if you used the devm_ variant here and in the other patches, the cleanup
> below and the sony_iio_remove() function could go away.
>
>> +     if (ret < 0) {
>> +             hid_err(hdev, "Unable to register iio device\n");
>> +             goto err;
>> +     }
>> +     return 0;
>> +
>> +err:
>> +     kfree(indio_dev);

Not to mention that the correct way to free an iio_dev is iio_device_free.

>> +     sc->indio_dev = NULL;
>> +     return ret;
>> +}
>> +
>> +static void sony_iio_remove(struct sony_sc *sc)
>> +{
>> +     if (!sc->indio_dev)
>> +             return;
>> +
>> +     iio_device_unregister(sc->indio_dev);
>> +     kfree(sc->indio_dev);
The same here.

>> +     sc->indio_dev = NULL;
>> +}

So, better use the devm_ variant at least for indio_dev allocation.

thanks,
Daniel.
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux