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

iio: set default trig->dev.parent

When allocated with [devm_]iio_trigger_alloc(), set trig device parent to
the device the trigger is allocated for by default.

It can always be reassigned in the probe routine.

Change iio_trigger_alloc() API to add the device pointer to be coherent
with devm_iio_trigger_alloc, using similar interface to
iio_device_alloc().

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210309193620.2176163-2-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gwendal Grignou and committed by
Jonathan Cameron
995071d3 7b8d045e

+40 -31
+1 -2
drivers/iio/accel/bma180.c
··· 1044 1044 indio_dev->info = &bma180_info; 1045 1045 1046 1046 if (client->irq > 0) { 1047 - data->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, 1047 + data->trig = iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, 1048 1048 indio_dev->id); 1049 1049 if (!data->trig) { 1050 1050 ret = -ENOMEM; ··· 1059 1059 goto err_trigger_free; 1060 1060 } 1061 1061 1062 - data->trig->dev.parent = dev; 1063 1062 data->trig->ops = &bma180_trigger_ops; 1064 1063 iio_trigger_set_drvdata(data->trig, indio_dev); 1065 1064 indio_dev->trig = iio_trigger_get(data->trig);
+3 -3
drivers/iio/adc/ad_sigma_delta.c
··· 475 475 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 476 476 int ret; 477 477 478 - sigma_delta->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, 479 - indio_dev->id); 478 + sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev, 479 + "%s-dev%d", indio_dev->name, 480 + indio_dev->id); 480 481 if (sigma_delta->trig == NULL) { 481 482 ret = -ENOMEM; 482 483 goto error_ret; ··· 497 496 sigma_delta->irq_dis = true; 498 497 disable_irq_nosync(sigma_delta->spi->irq); 499 498 } 500 - sigma_delta->trig->dev.parent = &sigma_delta->spi->dev; 501 499 iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta); 502 500 503 501 ret = iio_trigger_register(sigma_delta->trig);
+1 -2
drivers/iio/adc/at91_adc.c
··· 625 625 struct iio_trigger *trig; 626 626 int ret; 627 627 628 - trig = iio_trigger_alloc("%s-dev%d-%s", idev->name, 628 + trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name, 629 629 idev->id, trigger->name); 630 630 if (trig == NULL) 631 631 return NULL; 632 632 633 - trig->dev.parent = idev->dev.parent; 634 633 iio_trigger_set_drvdata(trig, idev); 635 634 trig->ops = &at91_adc_trigger_ops; 636 635
+2 -2
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
··· 255 255 return ret; 256 256 } 257 257 258 - trig = iio_trigger_alloc("%s-dev%d", name, indio_dev->id); 258 + trig = iio_trigger_alloc(indio_dev->dev.parent, 259 + "%s-dev%d", name, indio_dev->id); 259 260 if (trig == NULL) { 260 261 dev_err(&indio_dev->dev, "Trigger Allocate Failed\n"); 261 262 ret = -ENOMEM; 262 263 goto error_triggered_buffer_cleanup; 263 264 } 264 265 265 - trig->dev.parent = indio_dev->dev.parent; 266 266 iio_trigger_set_drvdata(trig, attrb); 267 267 trig->ops = &hid_sensor_trigger_ops; 268 268 ret = iio_trigger_register(trig);
+2 -2
drivers/iio/common/st_sensors/st_sensors_trigger.c
··· 123 123 unsigned long irq_trig; 124 124 int err; 125 125 126 - sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name); 126 + sdata->trig = iio_trigger_alloc(sdata->dev, "%s-trigger", 127 + indio_dev->name); 127 128 if (sdata->trig == NULL) { 128 129 dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n"); 129 130 return -ENOMEM; ··· 132 131 133 132 iio_trigger_set_drvdata(sdata->trig, indio_dev); 134 133 sdata->trig->ops = trigger_ops; 135 - sdata->trig->dev.parent = sdata->dev; 136 134 137 135 irq_trig = irqd_get_trigger_type(irq_get_irq_data(sdata->irq)); 138 136 /*
+1 -2
drivers/iio/gyro/itg3200_buffer.c
··· 113 113 int ret; 114 114 struct itg3200 *st = iio_priv(indio_dev); 115 115 116 - st->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, 116 + st->trig = iio_trigger_alloc(&st->i2c->dev, "%s-dev%d", indio_dev->name, 117 117 indio_dev->id); 118 118 if (!st->trig) 119 119 return -ENOMEM; ··· 127 127 goto error_free_trig; 128 128 129 129 130 - st->trig->dev.parent = &st->i2c->dev; 131 130 st->trig->ops = &itg3200_trigger_ops; 132 131 iio_trigger_set_drvdata(st->trig, indio_dev); 133 132 ret = iio_trigger_register(st->trig);
+23 -11
drivers/iio/industrialio-trigger.c
··· 514 514 trig->subirqs[d->irq - trig->subirq_base].enabled = true; 515 515 } 516 516 517 - static __printf(1, 0) 518 - struct iio_trigger *viio_trigger_alloc(const char *fmt, va_list vargs) 517 + static __printf(2, 0) 518 + struct iio_trigger *viio_trigger_alloc(struct device *parent, 519 + const char *fmt, 520 + va_list vargs) 519 521 { 520 522 struct iio_trigger *trig; 521 523 int i; ··· 526 524 if (!trig) 527 525 return NULL; 528 526 527 + trig->dev.parent = parent; 529 528 trig->dev.type = &iio_trig_type; 530 529 trig->dev.bus = &iio_bus_type; 531 530 device_initialize(&trig->dev); ··· 562 559 return NULL; 563 560 } 564 561 565 - struct iio_trigger *iio_trigger_alloc(const char *fmt, ...) 562 + /** 563 + * iio_trigger_alloc - Allocate a trigger 564 + * @parent: Device to allocate iio_trigger for 565 + * @fmt: trigger name format. If it includes format 566 + * specifiers, the additional arguments following 567 + * format are formatted and inserted in the resulting 568 + * string replacing their respective specifiers. 569 + * RETURNS: 570 + * Pointer to allocated iio_trigger on success, NULL on failure. 571 + */ 572 + struct iio_trigger *iio_trigger_alloc(struct device *parent, const char *fmt, ...) 566 573 { 567 574 struct iio_trigger *trig; 568 575 va_list vargs; 569 576 570 577 va_start(vargs, fmt); 571 - trig = viio_trigger_alloc(fmt, vargs); 578 + trig = viio_trigger_alloc(parent, fmt, vargs); 572 579 va_end(vargs); 573 580 574 581 return trig; ··· 599 586 600 587 /** 601 588 * devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc() 602 - * @dev: Device to allocate iio_trigger for 589 + * Managed iio_trigger_alloc. iio_trigger allocated with this function is 590 + * automatically freed on driver detach. 591 + * @parent: Device to allocate iio_trigger for 603 592 * @fmt: trigger name format. If it includes format 604 593 * specifiers, the additional arguments following 605 594 * format are formatted and inserted in the resulting 606 595 * string replacing their respective specifiers. 607 596 * 608 - * Managed iio_trigger_alloc. iio_trigger allocated with this function is 609 - * automatically freed on driver detach. 610 597 * 611 598 * RETURNS: 612 599 * Pointer to allocated iio_trigger on success, NULL on failure. 613 600 */ 614 - struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, 615 - const char *fmt, ...) 601 + struct iio_trigger *devm_iio_trigger_alloc(struct device *parent, const char *fmt, ...) 616 602 { 617 603 struct iio_trigger **ptr, *trig; 618 604 va_list vargs; ··· 623 611 624 612 /* use raw alloc_dr for kmalloc caller tracing */ 625 613 va_start(vargs, fmt); 626 - trig = viio_trigger_alloc(fmt, vargs); 614 + trig = viio_trigger_alloc(parent, fmt, vargs); 627 615 va_end(vargs); 628 616 if (trig) { 629 617 *ptr = trig; 630 - devres_add(dev, ptr); 618 + devres_add(parent, ptr); 631 619 } else { 632 620 devres_free(ptr); 633 621 }
+1 -1
drivers/iio/trigger/iio-trig-hrtimer.c
··· 135 135 if (!trig_info) 136 136 return ERR_PTR(-ENOMEM); 137 137 138 - trig_info->swt.trigger = iio_trigger_alloc("%s", name); 138 + trig_info->swt.trigger = iio_trigger_alloc(NULL, "%s", name); 139 139 if (!trig_info->swt.trigger) { 140 140 ret = -ENOMEM; 141 141 goto err_free_trig_info;
+1 -1
drivers/iio/trigger/iio-trig-interrupt.c
··· 45 45 46 46 irq = irq_res->start; 47 47 48 - trig = iio_trigger_alloc("irqtrig%d", irq); 48 + trig = iio_trigger_alloc(NULL, "irqtrig%d", irq); 49 49 if (!trig) { 50 50 ret = -ENOMEM; 51 51 goto error_ret;
+1 -1
drivers/iio/trigger/iio-trig-loop.c
··· 84 84 if (!trig_info) 85 85 return ERR_PTR(-ENOMEM); 86 86 87 - trig_info->swt.trigger = iio_trigger_alloc("%s", name); 87 + trig_info->swt.trigger = iio_trigger_alloc(NULL, "%s", name); 88 88 if (!trig_info->swt.trigger) { 89 89 ret = -ENOMEM; 90 90 goto err_free_trig_info;
+1 -2
drivers/iio/trigger/iio-trig-sysfs.c
··· 149 149 goto out1; 150 150 } 151 151 t->id = id; 152 - t->trig = iio_trigger_alloc("sysfstrig%d", id); 152 + t->trig = iio_trigger_alloc(&iio_sysfs_trig_dev, "sysfstrig%d", id); 153 153 if (!t->trig) { 154 154 ret = -ENOMEM; 155 155 goto free_t; ··· 157 157 158 158 t->trig->dev.groups = iio_sysfs_trigger_attr_groups; 159 159 t->trig->ops = &iio_sysfs_trigger_ops; 160 - t->trig->dev.parent = &iio_sysfs_trig_dev; 161 160 iio_trigger_set_drvdata(t->trig, t); 162 161 163 162 t->work = IRQ_WORK_INIT_HARD(iio_sysfs_trigger_work);
+1 -1
include/linux/iio/iio.h
··· 693 693 void iio_device_free(struct iio_dev *indio_dev); 694 694 struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv); 695 695 __printf(2, 3) 696 - struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, 696 + struct iio_trigger *devm_iio_trigger_alloc(struct device *parent, 697 697 const char *fmt, ...); 698 698 /** 699 699 * iio_buffer_enabled() - helper function to test if the buffer is enabled
+2 -1
include/linux/iio/trigger.h
··· 161 161 162 162 irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private); 163 163 164 - __printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...); 164 + __printf(2, 3) 165 + struct iio_trigger *iio_trigger_alloc(struct device *parent, const char *fmt, ...); 165 166 void iio_trigger_free(struct iio_trigger *trig); 166 167 167 168 /**