<snip>
quoted
+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?
quoted
+ 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.
quoted
+
+ 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.
quoted
+ 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.
quoted
+ 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.
quoted
+ sc->indio_dev = NULL;
+}
So, better use the devm_ variant at least for indio_dev allocation.
thanks,
Daniel.