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

dmaengine: qcom_hidma: cleanup sysfs entries during remove

The 4.8-rc8 kernel is printing duplicate file entry warnings while removing
the HIDMA object. This is caused by stale sysfs entries remaining from the
previous execution.

_sysfs_warn_dup+0x5c/0x78
sysfs_add_file_mode_ns+0x13c/0x1c0
sysfs_create_file_ns+0x2c/0x40
device_create_file+0x54/0xa0
hidma_probe+0x7c8/0x808

Create hidma_sysfs_init and hidma_sysfs_uninit functions and call them from
the probe and remove path. To do proper clean up, adding the attrs object
to the device data structure to keep it around until remove call is made.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>

authored by

Sinan Kaya and committed by
Vinod Koul
c6e4584d 8cc12b26

+24 -6
+21 -6
drivers/dma/qcom/hidma.c
··· 580 580 return strlen(buf); 581 581 } 582 582 583 - static int hidma_create_sysfs_entry(struct hidma_dev *dev, char *name, 584 - int mode) 583 + static inline void hidma_sysfs_uninit(struct hidma_dev *dev) 584 + { 585 + device_remove_file(dev->ddev.dev, dev->chid_attrs); 586 + } 587 + 588 + static struct device_attribute* 589 + hidma_create_sysfs_entry(struct hidma_dev *dev, char *name, int mode) 585 590 { 586 591 struct device_attribute *attrs; 587 592 char *name_copy; ··· 594 589 attrs = devm_kmalloc(dev->ddev.dev, sizeof(struct device_attribute), 595 590 GFP_KERNEL); 596 591 if (!attrs) 597 - return -ENOMEM; 592 + return NULL; 598 593 599 594 name_copy = devm_kstrdup(dev->ddev.dev, name, GFP_KERNEL); 600 595 if (!name_copy) 601 - return -ENOMEM; 596 + return NULL; 602 597 603 598 attrs->attr.name = name_copy; 604 599 attrs->attr.mode = mode; 605 600 attrs->show = hidma_show_values; 606 601 sysfs_attr_init(&attrs->attr); 607 602 608 - return device_create_file(dev->ddev.dev, attrs); 603 + return attrs; 604 + } 605 + 606 + static int hidma_sysfs_init(struct hidma_dev *dev) 607 + { 608 + dev->chid_attrs = hidma_create_sysfs_entry(dev, "chid", S_IRUGO); 609 + if (!dev->chid_attrs) 610 + return -ENOMEM; 611 + 612 + return device_create_file(dev->ddev.dev, dev->chid_attrs); 609 613 } 610 614 611 615 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN ··· 844 830 dmadev->irq = chirq; 845 831 tasklet_init(&dmadev->task, hidma_issue_task, (unsigned long)dmadev); 846 832 hidma_debug_init(dmadev); 847 - hidma_create_sysfs_entry(dmadev, "chid", S_IRUGO); 833 + hidma_sysfs_init(dmadev); 848 834 dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n"); 849 835 pm_runtime_mark_last_busy(dmadev->ddev.dev); 850 836 pm_runtime_put_autosuspend(dmadev->ddev.dev); ··· 877 863 hidma_free_msis(dmadev); 878 864 879 865 tasklet_kill(&dmadev->task); 866 + hidma_sysfs_uninit(dmadev); 880 867 hidma_debug_uninit(dmadev); 881 868 hidma_ll_uninit(dmadev->lldev); 882 869 hidma_free(dmadev);
+3
drivers/dma/qcom/hidma.h
··· 130 130 struct dentry *debugfs; 131 131 struct dentry *stats; 132 132 133 + /* sysfs entry for the channel id */ 134 + struct device_attribute *chid_attrs; 135 + 133 136 /* Task delivering issue_pending */ 134 137 struct tasklet_struct task; 135 138 };