From patchwork Mon Nov 14 19:34:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 9428291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 67EEF6047D for ; Mon, 14 Nov 2016 19:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59D3328A15 for ; Mon, 14 Nov 2016 19:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EC2128A38; Mon, 14 Nov 2016 19:35:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D400E28A15 for ; Mon, 14 Nov 2016 19:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934988AbcKNTe7 (ORCPT ); Mon, 14 Nov 2016 14:34:59 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:50236 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933841AbcKNTe6 (ORCPT ); Mon, 14 Nov 2016 14:34:58 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D0113613B9; Mon, 14 Nov 2016 19:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1479152097; bh=qeYkl2I+carDetnwnCOaLPANoDRO/ofFvIl+JFhQF7A=; h=Subject:References:To:From:Date:In-Reply-To:From; b=Bc0dpBhuGTno2sHu3PnNHZlV3FFbSKpM2Dst7dEOuf4gk1ud9CxPJDMU6Z7Tmn39o rMrC1H4AJEUwH8Jkh2yBDpvnOel9zlVKFurZjHcavKwLIbo9hRtdUWkP4eqv41ndK8 BWozKx6CySjDC1SMUd46dUniR30peteKYynhKDgA= Received: from [10.228.68.18] (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2FAC0613B1 for ; Mon, 14 Nov 2016 19:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1479152097; bh=qeYkl2I+carDetnwnCOaLPANoDRO/ofFvIl+JFhQF7A=; h=Subject:References:To:From:Date:In-Reply-To:From; b=Bc0dpBhuGTno2sHu3PnNHZlV3FFbSKpM2Dst7dEOuf4gk1ud9CxPJDMU6Z7Tmn39o rMrC1H4AJEUwH8Jkh2yBDpvnOel9zlVKFurZjHcavKwLIbo9hRtdUWkP4eqv41ndK8 BWozKx6CySjDC1SMUd46dUniR30peteKYynhKDgA= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 2FAC0613B1 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=okaya@codeaurora.org Subject: [PATCH V3] dmaengine: qcom_hidma: cleanup sysfs entries during remove References: <1479151406-30427-1-git-send-email-okaya@codeaurora.org> To: dmaengine From: Sinan Kaya X-Forwarded-Message-Id: <1479151406-30427-1-git-send-email-okaya@codeaurora.org> Message-ID: <30ae2aa4-b0b6-51f1-30b4-c36fa4a310b1@codeaurora.org> Date: Mon, 14 Nov 2016 14:34:53 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1479151406-30427-1-git-send-email-okaya@codeaurora.org> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/dma/qcom/hidma.c | 27 +++++++++++++++++++++------ drivers/dma/qcom/hidma.h | 3 +++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/dma/qcom/hidma.c b/drivers/dma/qcom/hidma.c index 10425e1..248e74b 100644 --- a/drivers/dma/qcom/hidma.c +++ b/drivers/dma/qcom/hidma.c @@ -580,8 +580,13 @@ static ssize_t hidma_show_values(struct device *dev, return strlen(buf); } -static int hidma_create_sysfs_entry(struct hidma_dev *dev, char *name, - int mode) +static inline void hidma_sysfs_uninit(struct hidma_dev *dev) +{ + device_remove_file(dev->ddev.dev, dev->chid_attrs); +} + +static struct device_attribute* +hidma_create_sysfs_entry(struct hidma_dev *dev, char *name, int mode) { struct device_attribute *attrs; char *name_copy; @@ -589,18 +594,27 @@ static int hidma_create_sysfs_entry(struct hidma_dev *dev, char *name, attrs = devm_kmalloc(dev->ddev.dev, sizeof(struct device_attribute), GFP_KERNEL); if (!attrs) - return -ENOMEM; + return NULL; name_copy = devm_kstrdup(dev->ddev.dev, name, GFP_KERNEL); if (!name_copy) - return -ENOMEM; + return NULL; attrs->attr.name = name_copy; attrs->attr.mode = mode; attrs->show = hidma_show_values; sysfs_attr_init(&attrs->attr); - return device_create_file(dev->ddev.dev, attrs); + return attrs; +} + +static int hidma_sysfs_init(struct hidma_dev *dev) +{ + dev->chid_attrs = hidma_create_sysfs_entry(dev, "chid", S_IRUGO); + if (!dev->chid_attrs) + return -ENOMEM; + + return device_create_file(dev->ddev.dev, dev->chid_attrs); } #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN @@ -830,7 +844,7 @@ static int hidma_probe(struct platform_device *pdev) dmadev->irq = chirq; tasklet_init(&dmadev->task, hidma_issue_task, (unsigned long)dmadev); hidma_debug_init(dmadev); - hidma_create_sysfs_entry(dmadev, "chid", S_IRUGO); + hidma_sysfs_init(dmadev); dev_info(&pdev->dev, "HI-DMA engine driver registration complete\n"); pm_runtime_mark_last_busy(dmadev->ddev.dev); pm_runtime_put_autosuspend(dmadev->ddev.dev); @@ -863,6 +877,7 @@ static int hidma_remove(struct platform_device *pdev) hidma_free_msis(dmadev); tasklet_kill(&dmadev->task); + hidma_sysfs_uninit(dmadev); hidma_debug_uninit(dmadev); hidma_ll_uninit(dmadev->lldev); hidma_free(dmadev); diff --git a/drivers/dma/qcom/hidma.h b/drivers/dma/qcom/hidma.h index 05f8ba4..c7d0142 100644 --- a/drivers/dma/qcom/hidma.h +++ b/drivers/dma/qcom/hidma.h @@ -130,6 +130,9 @@ struct hidma_dev { struct dentry *debugfs; struct dentry *stats; + /* sysfs entry for the channel id */ + struct device_attribute *chid_attrs; + /* Task delivering issue_pending */ struct tasklet_struct task; };