Skip to content

Commit 78289b4

Browse files
commodojic23
authored andcommitted
iio: core: pass parent device as parameter during allocation
The change passes the parent device to the iio_device_alloc() call. This also updates the devm_iio_device_alloc() call to consider the device object as the parent device by default. Having it passed like this, should ensure that any IIO device object already has a device object as parent, allowing for neater control, like passing the 'indio_dev' object for other stuff [like buffers/triggers/etc], and potentially creating iiom_xxx(indio_dev) functions. With this patch, only the 'drivers/platform/x86/toshiba_acpi.c' needs an update to pass the parent object as a parameter. In the next patch all devm_iio_device_alloc() calls will be handled. Acked-by: Andy Shevchenko <[email protected]> Signed-off-by: Alexandru Ardelean <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 9ca3941 commit 78289b4

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

drivers/iio/dummy/iio_simple_dummy.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
566566
struct iio_dev *indio_dev;
567567
struct iio_dummy_state *st;
568568
struct iio_sw_device *swd;
569+
struct device *parent = NULL;
570+
571+
/*
572+
* With hardware: Set the parent device.
573+
* parent = &spi->dev;
574+
* parent = &client->dev;
575+
*/
569576

570577
swd = kzalloc(sizeof(*swd), GFP_KERNEL);
571578
if (!swd) {
@@ -580,7 +587,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
580587
* It also has a region (accessed by iio_priv()
581588
* for chip specific state information.
582589
*/
583-
indio_dev = iio_device_alloc(sizeof(*st));
590+
indio_dev = iio_device_alloc(parent, sizeof(*st));
584591
if (!indio_dev) {
585592
ret = -ENOMEM;
586593
goto error_ret;
@@ -590,11 +597,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
590597
mutex_init(&st->lock);
591598

592599
iio_dummy_init_device(indio_dev);
593-
/*
594-
* With hardware: Set the parent device.
595-
* indio_dev->dev.parent = &spi->dev;
596-
* indio_dev->dev.parent = &client->dev;
597-
*/
598600

599601
/*
600602
* Make the iio_dev struct available to remove function.

drivers/iio/industrialio-core.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ struct device_type iio_device_type = {
14931493
* iio_device_alloc() - allocate an iio_dev from a driver
14941494
* @sizeof_priv: Space to allocate for private structure.
14951495
**/
1496-
struct iio_dev *iio_device_alloc(int sizeof_priv)
1496+
struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
14971497
{
14981498
struct iio_dev *dev;
14991499
size_t alloc_size;
@@ -1510,6 +1510,7 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
15101510
if (!dev)
15111511
return NULL;
15121512

1513+
dev->dev.parent = parent;
15131514
dev->dev.groups = dev->groups;
15141515
dev->dev.type = &iio_device_type;
15151516
dev->dev.bus = &iio_bus_type;
@@ -1551,7 +1552,7 @@ static void devm_iio_device_release(struct device *dev, void *res)
15511552

15521553
/**
15531554
* devm_iio_device_alloc - Resource-managed iio_device_alloc()
1554-
* @dev: Device to allocate iio_dev for
1555+
* @parent: Device to allocate iio_dev for, and parent for this IIO device
15551556
* @sizeof_priv: Space to allocate for private structure.
15561557
*
15571558
* Managed iio_device_alloc. iio_dev allocated with this function is
@@ -1560,7 +1561,7 @@ static void devm_iio_device_release(struct device *dev, void *res)
15601561
* RETURNS:
15611562
* Pointer to allocated iio_dev on success, NULL on failure.
15621563
*/
1563-
struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
1564+
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
15641565
{
15651566
struct iio_dev **ptr, *iio_dev;
15661567

@@ -1569,10 +1570,10 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
15691570
if (!ptr)
15701571
return NULL;
15711572

1572-
iio_dev = iio_device_alloc(sizeof_priv);
1573+
iio_dev = iio_device_alloc(parent, sizeof_priv);
15731574
if (iio_dev) {
15741575
*ptr = iio_dev;
1575-
devres_add(dev, ptr);
1576+
devres_add(parent, ptr);
15761577
} else {
15771578
devres_free(ptr);
15781579
}

drivers/platform/x86/toshiba_acpi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,7 +3114,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
31143114

31153115
toshiba_accelerometer_available(dev);
31163116
if (dev->accelerometer_supported) {
3117-
dev->indio_dev = iio_device_alloc(sizeof(*dev));
3117+
dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev));
31183118
if (!dev->indio_dev) {
31193119
pr_err("Unable to allocate iio device\n");
31203120
goto iio_error;
@@ -3124,7 +3124,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
31243124

31253125
dev->indio_dev->info = &toshiba_iio_accel_info;
31263126
dev->indio_dev->name = "Toshiba accelerometer";
3127-
dev->indio_dev->dev.parent = &acpi_dev->dev;
31283127
dev->indio_dev->modes = INDIO_DIRECT_MODE;
31293128
dev->indio_dev->channels = toshiba_iio_accel_channels;
31303129
dev->indio_dev->num_channels =

drivers/staging/iio/Documentation/device.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ The crucial structure for device drivers in iio is iio_dev.
88

99
First allocate one using:
1010

11-
struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));
11+
struct iio_dev *indio_dev = iio_device_alloc(parent, sizeof(struct chip_state));
1212
where chip_state is a structure of local state data for this instance of
1313
the chip.
1414

1515
That data can be accessed using iio_priv(struct iio_dev *).
1616

1717
Then fill in the following:
1818

19-
- indio_dev->dev.parent
20-
Struct device associated with the underlying hardware.
2119
- indio_dev->name
2220
Name of the device being driven - made available as the name
2321
attribute in sysfs.

include/linux/iio/iio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev)
676676

677677
/* Can we make this smaller? */
678678
#define IIO_ALIGN L1_CACHE_BYTES
679-
struct iio_dev *iio_device_alloc(int sizeof_priv);
679+
struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv);
680680

681681
static inline void *iio_priv(const struct iio_dev *indio_dev)
682682
{
@@ -690,7 +690,7 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv)
690690
}
691691

692692
void iio_device_free(struct iio_dev *indio_dev);
693-
struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
693+
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv);
694694
struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
695695
const char *fmt, ...);
696696
/**

0 commit comments

Comments
 (0)