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

Configure Feed

Select the types of activity you want to include in your feed.

iio: trigger: move trig->owner init to trigger allocate() stage

To provide a new IIO trigger to the IIO core, usually driver executes the
following pipeline: allocate()/register()/get(). Before, IIO core assigned
trig->owner as a pointer to the module which registered this trigger at
the register() stage. But actually the trigger object is owned by the
module earlier, on the allocate() stage, when trigger object is
successfully allocated for the driver.

This patch moves trig->owner initialization from register()
stage of trigger initialization pipeline to allocate() stage to
eliminate all misunderstandings and time gaps between trigger object
creation and owner acquiring.

Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
Link: https://lore.kernel.org/r/20220601174837.20292-1-ddrokosov@sberdevices.ru
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Dmitry Rokosov and committed by
Jonathan Cameron
bc72d938 17b5a7f6

+41 -35
+25 -21
drivers/iio/industrialio-trigger.c
··· 63 63 64 64 static struct iio_trigger *__iio_trigger_find_by_name(const char *name); 65 65 66 - int __iio_trigger_register(struct iio_trigger *trig_info, 67 - struct module *this_mod) 66 + int iio_trigger_register(struct iio_trigger *trig_info) 68 67 { 69 68 int ret; 70 - 71 - trig_info->owner = this_mod; 72 69 73 70 trig_info->id = ida_alloc(&iio_trigger_ida, GFP_KERNEL); 74 71 if (trig_info->id < 0) ··· 97 100 ida_free(&iio_trigger_ida, trig_info->id); 98 101 return ret; 99 102 } 100 - EXPORT_SYMBOL(__iio_trigger_register); 103 + EXPORT_SYMBOL(iio_trigger_register); 101 104 102 105 void iio_trigger_unregister(struct iio_trigger *trig_info) 103 106 { ··· 544 547 trig->subirqs[d->irq - trig->subirq_base].enabled = true; 545 548 } 546 549 547 - static __printf(2, 0) 550 + static __printf(3, 0) 548 551 struct iio_trigger *viio_trigger_alloc(struct device *parent, 552 + struct module *this_mod, 549 553 const char *fmt, 550 554 va_list vargs) 551 555 { ··· 576 578 577 579 INIT_LIST_HEAD(&trig->list); 578 580 581 + trig->owner = this_mod; 582 + 579 583 trig->subirq_chip.name = trig->name; 580 584 trig->subirq_chip.irq_mask = &iio_trig_subirqmask; 581 585 trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; ··· 598 598 } 599 599 600 600 /** 601 - * iio_trigger_alloc - Allocate a trigger 601 + * __iio_trigger_alloc - Allocate a trigger 602 602 * @parent: Device to allocate iio_trigger for 603 + * @this_mod: module allocating the trigger 603 604 * @fmt: trigger name format. If it includes format 604 605 * specifiers, the additional arguments following 605 606 * format are formatted and inserted in the resulting ··· 608 607 * RETURNS: 609 608 * Pointer to allocated iio_trigger on success, NULL on failure. 610 609 */ 611 - struct iio_trigger *iio_trigger_alloc(struct device *parent, const char *fmt, ...) 610 + struct iio_trigger *__iio_trigger_alloc(struct device *parent, 611 + struct module *this_mod, 612 + const char *fmt, ...) 612 613 { 613 614 struct iio_trigger *trig; 614 615 va_list vargs; 615 616 616 617 va_start(vargs, fmt); 617 - trig = viio_trigger_alloc(parent, fmt, vargs); 618 + trig = viio_trigger_alloc(parent, this_mod, fmt, vargs); 618 619 va_end(vargs); 619 620 620 621 return trig; 621 622 } 622 - EXPORT_SYMBOL(iio_trigger_alloc); 623 + EXPORT_SYMBOL(__iio_trigger_alloc); 623 624 624 625 void iio_trigger_free(struct iio_trigger *trig) 625 626 { ··· 636 633 } 637 634 638 635 /** 639 - * devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc() 636 + * __devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc() 640 637 * Managed iio_trigger_alloc. iio_trigger allocated with this function is 641 638 * automatically freed on driver detach. 642 639 * @parent: Device to allocate iio_trigger for 640 + * @this_mod: module allocating the trigger 643 641 * @fmt: trigger name format. If it includes format 644 642 * specifiers, the additional arguments following 645 643 * format are formatted and inserted in the resulting ··· 650 646 * RETURNS: 651 647 * Pointer to allocated iio_trigger on success, NULL on failure. 652 648 */ 653 - struct iio_trigger *devm_iio_trigger_alloc(struct device *parent, const char *fmt, ...) 649 + struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent, 650 + struct module *this_mod, 651 + const char *fmt, ...) 654 652 { 655 653 struct iio_trigger **ptr, *trig; 656 654 va_list vargs; ··· 664 658 665 659 /* use raw alloc_dr for kmalloc caller tracing */ 666 660 va_start(vargs, fmt); 667 - trig = viio_trigger_alloc(parent, fmt, vargs); 661 + trig = viio_trigger_alloc(parent, this_mod, fmt, vargs); 668 662 va_end(vargs); 669 663 if (trig) { 670 664 *ptr = trig; ··· 675 669 676 670 return trig; 677 671 } 678 - EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc); 672 + EXPORT_SYMBOL_GPL(__devm_iio_trigger_alloc); 679 673 680 674 static void devm_iio_trigger_unreg(void *trigger_info) 681 675 { ··· 683 677 } 684 678 685 679 /** 686 - * __devm_iio_trigger_register - Resource-managed iio_trigger_register() 680 + * devm_iio_trigger_register - Resource-managed iio_trigger_register() 687 681 * @dev: device this trigger was allocated for 688 682 * @trig_info: trigger to register 689 - * @this_mod: module registering the trigger 690 683 * 691 684 * Managed iio_trigger_register(). The IIO trigger registered with this 692 685 * function is automatically unregistered on driver detach. This function ··· 695 690 * RETURNS: 696 691 * 0 on success, negative error number on failure. 697 692 */ 698 - int __devm_iio_trigger_register(struct device *dev, 699 - struct iio_trigger *trig_info, 700 - struct module *this_mod) 693 + int devm_iio_trigger_register(struct device *dev, 694 + struct iio_trigger *trig_info) 701 695 { 702 696 int ret; 703 697 704 - ret = __iio_trigger_register(trig_info, this_mod); 698 + ret = iio_trigger_register(trig_info); 705 699 if (ret) 706 700 return ret; 707 701 708 702 return devm_add_action_or_reset(dev, devm_iio_trigger_unreg, trig_info); 709 703 } 710 - EXPORT_SYMBOL_GPL(__devm_iio_trigger_register); 704 + EXPORT_SYMBOL_GPL(devm_iio_trigger_register); 711 705 712 706 bool iio_trigger_using_own(struct iio_dev *indio_dev) 713 707 {
+6 -3
include/linux/iio/iio.h
··· 727 727 728 728 void iio_device_free(struct iio_dev *indio_dev); 729 729 struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv); 730 - __printf(2, 3) 731 - struct iio_trigger *devm_iio_trigger_alloc(struct device *parent, 732 - const char *fmt, ...); 733 730 731 + #define devm_iio_trigger_alloc(parent, fmt, ...) \ 732 + __devm_iio_trigger_alloc((parent), THIS_MODULE, (fmt), ##__VA_ARGS__) 733 + __printf(3, 4) 734 + struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent, 735 + struct module *this_mod, 736 + const char *fmt, ...); 734 737 /** 735 738 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry 736 739 * @indio_dev: IIO device structure for device
+10 -11
include/linux/iio/trigger.h
··· 131 131 * iio_trigger_register() - register a trigger with the IIO core 132 132 * @trig_info: trigger to be registered 133 133 **/ 134 - #define iio_trigger_register(trig_info) \ 135 - __iio_trigger_register((trig_info), THIS_MODULE) 136 - int __iio_trigger_register(struct iio_trigger *trig_info, 137 - struct module *this_mod); 134 + int iio_trigger_register(struct iio_trigger *trig_info); 138 135 139 - #define devm_iio_trigger_register(dev, trig_info) \ 140 - __devm_iio_trigger_register((dev), (trig_info), THIS_MODULE) 141 - int __devm_iio_trigger_register(struct device *dev, 142 - struct iio_trigger *trig_info, 143 - struct module *this_mod); 136 + int devm_iio_trigger_register(struct device *dev, 137 + struct iio_trigger *trig_info); 144 138 145 139 /** 146 140 * iio_trigger_unregister() - unregister a trigger from the core ··· 162 168 163 169 irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private); 164 170 165 - __printf(2, 3) 166 - struct iio_trigger *iio_trigger_alloc(struct device *parent, const char *fmt, ...); 171 + #define iio_trigger_alloc(parent, fmt, ...) \ 172 + __iio_trigger_alloc((parent), THIS_MODULE, (fmt), ##__VA_ARGS__) 173 + 174 + __printf(3, 4) 175 + struct iio_trigger *__iio_trigger_alloc(struct device *parent, 176 + struct module *this_mod, 177 + const char *fmt, ...); 167 178 void iio_trigger_free(struct iio_trigger *trig); 168 179 169 180 /**