From patchwork Tue Nov 6 20:35:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatolij Gustschin X-Patchwork-Id: 10671373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90EDC15E9 for ; Tue, 6 Nov 2018 20:35:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 832152A1CB for ; Tue, 6 Nov 2018 20:35:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 744632AB0F; Tue, 6 Nov 2018 20:35:17 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 B6E032A1CB for ; Tue, 6 Nov 2018 20:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726960AbeKGGCQ (ORCPT ); Wed, 7 Nov 2018 01:02:16 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:55492 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730742AbeKGGCQ (ORCPT ); Wed, 7 Nov 2018 01:02:16 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42qLrx75mXz1qxkX; Tue, 6 Nov 2018 21:35:13 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42qLrx6frZz1qr2H; Tue, 6 Nov 2018 21:35:13 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id JXlzAAAbYS3Z; Tue, 6 Nov 2018 21:35:12 +0100 (CET) X-Auth-Info: omY8eEdoA9A3db5G0k6660tVmotWyE1WI0GYqV1P9Nk= Received: from crub.agik.hopto.org (p5088702D.dip0.t-ipconnect.de [80.136.112.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 6 Nov 2018 21:35:12 +0100 (CET) From: Anatolij Gustschin To: linux-fpga@vger.kernel.org Cc: atull@kernel.org, mdf@kernel.org Subject: [PATCH] fpga: altera-cvp: fix probing for multiple FPGAs on the bus Date: Tue, 6 Nov 2018 21:35:12 +0100 Message-Id: <20181106203512.4509-1-agust@denx.de> X-Mailer: git-send-email 2.17.1 Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently registering CvP managers works only for first probed CvP device, for all other devices it is refused due to duplicated chkcfg sysfs entry: fpga_manager fpga3: Altera CvP FPGA Manager @0000:0c:00.0 registered sysfs: cannot create duplicate filename '/bus/pci/drivers/altera-cvp/chkcfg' CPU: 0 PID: 3808 Comm: bash Tainted: G O 4.19.0-custom+ #5 Call Trace: dump_stack+0x46/0x5b sysfs_warn_dup+0x53/0x60 sysfs_add_file_mode_ns+0x16d/0x180 sysfs_create_file_ns+0x51/0x60 altera_cvp_probe+0x16f/0x2a0 [altera_cvp] local_pci_probe+0x3f/0xa0 ? pci_match_device+0xb1/0xf0 pci_device_probe+0x116/0x170 really_probe+0x21b/0x2c0 driver_probe_device+0x4b/0xe0 bind_store+0xcb/0x130 kernfs_fop_write+0xfd/0x180 __vfs_write+0x21/0x150 ? selinux_file_permission+0xdc/0x130 vfs_write+0xa8/0x1a0 ? find_vma+0xd/0x60 ksys_write+0x3d/0x90 do_syscall_64+0x44/0xf0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 ... altera-cvp 0000:0c:00.0: Can't create sysfs chkcfg file fpga_manager fpga3: fpga_mgr_unregister Altera CvP FPGA Manager @0000:0c:00.0 Skip chkcfg creation for all but first probed device. Remove chkcfg interface when last potential user has gone. Signed-off-by: Anatolij Gustschin --- drivers/fpga/altera-cvp.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c index 144fa2a4d4cc..381d0c42450f 100644 --- a/drivers/fpga/altera-cvp.c +++ b/drivers/fpga/altera-cvp.c @@ -60,6 +60,7 @@ /* Optional CvP config error status check for debugging */ static bool altera_cvp_chkcfg; +static unsigned int altera_cvp_cnt; struct altera_cvp_conf { struct fpga_manager *mgr; @@ -466,12 +467,15 @@ static int altera_cvp_probe(struct pci_dev *pdev, if (ret) goto err_unmap; - ret = driver_create_file(&altera_cvp_driver.driver, - &driver_attr_chkcfg); - if (ret) { - dev_err(&pdev->dev, "Can't create sysfs chkcfg file\n"); - fpga_mgr_unregister(mgr); - goto err_unmap; + if (!altera_cvp_cnt++) { + ret = driver_create_file(&altera_cvp_driver.driver, + &driver_attr_chkcfg); + if (ret) { + dev_err(&pdev->dev, "Can't create sysfs chkcfg file\n"); + fpga_mgr_unregister(mgr); + altera_cvp_cnt--; + goto err_unmap; + } } return 0; @@ -492,7 +496,11 @@ static void altera_cvp_remove(struct pci_dev *pdev) struct altera_cvp_conf *conf = mgr->priv; u16 cmd; - driver_remove_file(&altera_cvp_driver.driver, &driver_attr_chkcfg); + if (!--altera_cvp_cnt) { + driver_remove_file(&altera_cvp_driver.driver, + &driver_attr_chkcfg); + } + fpga_mgr_unregister(mgr); if (conf->map) pci_iounmap(pdev, conf->map);