Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: move 'indio_dev->info' null check first in __iio_device_register()

Moves this to be the first check, as it's very simple and fails the
registration earlier, instead of potentially initializing the
'indio_dev->label' and checking for duplicate indexes, and then failing
with this simple-check.

This is a minor optimization, since '__iio_device_register()' will waste
fewer validation cycles in case 'indio_dev->info' is NULL.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
a17cb784 2e036804

+3 -3
+3 -3
drivers/iio/industrialio-core.c
··· 1711 1711 { 1712 1712 int ret; 1713 1713 1714 + if (!indio_dev->info) 1715 + return -EINVAL; 1716 + 1714 1717 indio_dev->driver_module = this_mod; 1715 1718 /* If the calling driver did not initialize of_node, do it here */ 1716 1719 if (!indio_dev->dev.of_node && indio_dev->dev.parent) ··· 1725 1722 ret = iio_check_unique_scan_index(indio_dev); 1726 1723 if (ret < 0) 1727 1724 return ret; 1728 - 1729 - if (!indio_dev->info) 1730 - return -EINVAL; 1731 1725 1732 1726 /* configure elements for the chrdev */ 1733 1727 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);