From patchwork Mon Feb 14 07:16:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kumar, M Chetan" X-Patchwork-Id: 12745042 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 851C3C433F5 for ; Mon, 14 Feb 2022 07:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229800AbiBNHHv (ORCPT ); Mon, 14 Feb 2022 02:07:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241242AbiBNHHr (ORCPT ); Mon, 14 Feb 2022 02:07:47 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3B9B57B3D for ; Sun, 13 Feb 2022 23:07:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644822459; x=1676358459; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4fQ5AqI/mm8qssZmVts1W66hjv3QYQyfAYacXYFWGSU=; b=FAcoWNvtaM3nx85n2zuDoaOpRLqBpM/RGANG84th1C8NsoIiwgasBWC0 pJIjICd80uZ3Oi2l6Xetm8tnManjpmvaAg7V+Jd46t1VIsjFFydrzPUCn Tg1uHbn5wLqKTVuV3IYV3Qp4ACJJS/H7FHG/PJnMnG9fv3kYer8N8PXvh ovNE2fqSrGrMxDD3r1Iv7lbarYLsdnUlIL1ucsxjk/p8M9nLyCW9mXT8E 4s0XdyrQNntg/LvpZAwKgfuEfRHpZ6p3jevdS3YfclGq2JIpAlzwHeu7S tVQvagUUsu60gmnIDwiG+AgFBFzAUCyYqiLAMehPmP73385cnc9l8t0fy A==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="248862568" X-IronPort-AV: E=Sophos;i="5.88,367,1635231600"; d="scan'208";a="248862568" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 23:07:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,367,1635231600"; d="scan'208";a="680286218" Received: from ccgwwan-desktop15.iind.intel.com (HELO BSWCG005.iind.intel.com) ([10.224.174.19]) by fmsmga001.fm.intel.com with ESMTP; 13 Feb 2022 23:07:36 -0800 From: M Chetan Kumar To: netdev@vger.kernel.org Cc: kuba@kernel.org, davem@davemloft.net, johannes@sipsolutions.net, ryazanov.s.a@gmail.com, loic.poulain@linaro.org, krishna.c.sudi@intel.com, m.chetan.kumar@intel.com, m.chetan.kumar@linux.intel.com, linuxwwan@intel.com Subject: [PATCH net-next 1/2] net: wwan: debugfs obtained dev reference not dropped Date: Mon, 14 Feb 2022 12:46:52 +0530 Message-Id: <20220214071653.813010-2-m.chetan.kumar@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214071653.813010-1-m.chetan.kumar@linux.intel.com> References: <20220214071653.813010-1-m.chetan.kumar@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org WWAN driver call's wwan_get_debugfs_dir() to obtain WWAN debugfs dir entry. As part of this procedure it returns a reference to a found device. Since there is no debugfs interface available at WWAN subsystem, it is not possible to drop dev reference post debugfs use. This leads to side effects like post wwan driver load and reload the wwan instance gets increment from wwanX to wwanX+1. A new debugfs interface is added in wwan subsystem so that wwan driver can drop the obtained dev reference post debugfs use. void wwan_put_debugfs_dir(struct dentry *dir) Signed-off-by: M Chetan Kumar --- drivers/net/wwan/wwan_core.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/wwan.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 1508dc2a497b..147b88464cbd 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -160,6 +160,42 @@ struct dentry *wwan_get_debugfs_dir(struct device *parent) return wwandev->debugfs_dir; } EXPORT_SYMBOL_GPL(wwan_get_debugfs_dir); + +static int wwan_dev_debugfs_match(struct device *dev, const void *dir) +{ + struct wwan_device *wwandev; + + if (dev->type != &wwan_dev_type) + return 0; + + wwandev = to_wwan_dev(dev); + + return wwandev->debugfs_dir == dir; +} + +static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir) +{ + struct device *dev; + + dev = class_find_device(wwan_class, NULL, dir, wwan_dev_debugfs_match); + if (!dev) + return ERR_PTR(-ENODEV); + + return to_wwan_dev(dev); +} + +void wwan_put_debugfs_dir(struct dentry *dir) +{ + struct wwan_device *wwandev = wwan_dev_get_by_debugfs(dir); + + if (WARN_ON(IS_ERR(wwandev))) + return; + + /* wwan_dev_get_by_debugfs() also got a reference */ + put_device(&wwandev->dev); + put_device(&wwandev->dev); +} +EXPORT_SYMBOL_GPL(wwan_put_debugfs_dir); #endif /* This function allocates and registers a new WWAN device OR if a WWAN device diff --git a/include/linux/wwan.h b/include/linux/wwan.h index afb3334ec8c5..5ce2acf444fb 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -174,11 +174,13 @@ void wwan_unregister_ops(struct device *parent); #ifdef CONFIG_WWAN_DEBUGFS struct dentry *wwan_get_debugfs_dir(struct device *parent); +void wwan_put_debugfs_dir(struct dentry *dir); #else static inline struct dentry *wwan_get_debugfs_dir(struct device *parent) { return ERR_PTR(-ENODEV); } +static inline void wwan_put_debugfs_dir(struct dentry *dir) {} #endif #endif /* __WWAN_H */ From patchwork Mon Feb 14 07:16:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kumar, M Chetan" X-Patchwork-Id: 12745043 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8D0DC433FE for ; Mon, 14 Feb 2022 07:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241255AbiBNHHv (ORCPT ); Mon, 14 Feb 2022 02:07:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241251AbiBNHHu (ORCPT ); Mon, 14 Feb 2022 02:07:50 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBA405839A for ; Sun, 13 Feb 2022 23:07:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644822462; x=1676358462; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q7OR1YzRcT8E8CLxMwg0rSxb27SP6B3vno/We1jGHWo=; b=mTqNMFRzp3Xx5eReOqrHAUCUFUUZLowcLc0FaC8SpOGIN9o5xJZbbYVs 5ciNZosIgYYdbFELTjTTf0LMKpaPoOS0vPQG32ToP7TruTaRYzbD2QAB0 IUp2yxlFo+2Y75ek9xg37NCJq3Z7B0T32LSc9PzH9Txj8/JAzveQK0BeS sSBQQ2YWXQ9od6PpMiEdonBN1gCQQFmmyKZNvoG+rNZhAAOyVAB+VQ8cp b/a3bIvwyX2dlGRWXFWbD8vTsiyyU/C67+fLKrIXJnC5zr6Pwn/QngvRM Yjq5jrKGRjs7khSWaEeNHHuQn7pKBwoIMpgr4q+iGAOrQLD6IAq+OQZeG A==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="248862574" X-IronPort-AV: E=Sophos;i="5.88,367,1635231600"; d="scan'208";a="248862574" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 23:07:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,367,1635231600"; d="scan'208";a="680286243" Received: from ccgwwan-desktop15.iind.intel.com (HELO BSWCG005.iind.intel.com) ([10.224.174.19]) by fmsmga001.fm.intel.com with ESMTP; 13 Feb 2022 23:07:40 -0800 From: M Chetan Kumar To: netdev@vger.kernel.org Cc: kuba@kernel.org, davem@davemloft.net, johannes@sipsolutions.net, ryazanov.s.a@gmail.com, loic.poulain@linaro.org, krishna.c.sudi@intel.com, m.chetan.kumar@intel.com, m.chetan.kumar@linux.intel.com, linuxwwan@intel.com Subject: [PATCH net-next 2/2] net: wwan: iosm: drop debugfs dev reference Date: Mon, 14 Feb 2022 12:46:53 +0530 Message-Id: <20220214071653.813010-3-m.chetan.kumar@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214071653.813010-1-m.chetan.kumar@linux.intel.com> References: <20220214071653.813010-1-m.chetan.kumar@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Post debugfs use call wwan_put_debugfs_dir()to drop debugfs dev reference. Signed-off-by: M Chetan Kumar --- drivers/net/wwan/iosm/iosm_ipc_debugfs.c | 5 +++-- drivers/net/wwan/iosm/iosm_ipc_imem.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_debugfs.c b/drivers/net/wwan/iosm/iosm_ipc_debugfs.c index f2f57751a7d2..e916139b8cd4 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_debugfs.c +++ b/drivers/net/wwan/iosm/iosm_ipc_debugfs.c @@ -12,10 +12,10 @@ void ipc_debugfs_init(struct iosm_imem *ipc_imem) { - struct dentry *debugfs_pdev = wwan_get_debugfs_dir(ipc_imem->dev); + ipc_imem->debugfs_wwan_dir = wwan_get_debugfs_dir(ipc_imem->dev); ipc_imem->debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, - debugfs_pdev); + ipc_imem->debugfs_wwan_dir); ipc_imem->trace = ipc_trace_init(ipc_imem); if (!ipc_imem->trace) @@ -26,4 +26,5 @@ void ipc_debugfs_deinit(struct iosm_imem *ipc_imem) { ipc_trace_deinit(ipc_imem->trace); debugfs_remove_recursive(ipc_imem->debugfs_dir); + wwan_put_debugfs_dir(ipc_imem->debugfs_wwan_dir); } diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.h b/drivers/net/wwan/iosm/iosm_ipc_imem.h index 5682e8d6be7b..e700dc8bfe0a 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_imem.h +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.h @@ -341,6 +341,7 @@ enum ipc_phase { * @ev_mux_net_transmit_pending:0 means inform the IPC tasklet to pass * @reset_det_n: Reset detect flag * @pcie_wake_n: Pcie wake flag + * @debugfs_wwan_dir: WWAN Debug FS directory entry * @debugfs_dir: Debug FS directory for driver-specific entries */ struct iosm_imem { @@ -384,6 +385,7 @@ struct iosm_imem { reset_det_n:1, pcie_wake_n:1; #ifdef CONFIG_WWAN_DEBUGFS + struct dentry *debugfs_wwan_dir; struct dentry *debugfs_dir; #endif };