1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
4 #include <linux/debugfs.h>
6 #include <linux/kernel.h>
7 #include <linux/slab.h>
11 static struct dentry *nsim_sdev_ddir;
13 static u32 nsim_sdev_id;
15 struct netdevsim_shared_dev *nsim_sdev_get(struct netdevsim *joinns)
17 struct netdevsim_shared_dev *sdev;
18 char sdev_ddir_name[10];
22 if (WARN_ON(!joinns->sdev))
23 return ERR_PTR(-EINVAL);
29 sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
31 return ERR_PTR(-ENOMEM);
33 sdev->switch_id = nsim_sdev_id++;
35 sprintf(sdev_ddir_name, "%u", sdev->switch_id);
36 sdev->ddir = debugfs_create_dir(sdev_ddir_name, nsim_sdev_ddir);
37 if (IS_ERR_OR_NULL(sdev->ddir)) {
38 err = PTR_ERR_OR_ZERO(sdev->ddir) ?: -EINVAL;
50 void nsim_sdev_put(struct netdevsim_shared_dev *sdev)
54 debugfs_remove_recursive(sdev->ddir);
58 int nsim_sdev_init(void)
60 nsim_sdev_ddir = debugfs_create_dir(DRV_NAME "_sdev", NULL);
61 if (IS_ERR_OR_NULL(nsim_sdev_ddir))
66 void nsim_sdev_exit(void)
68 debugfs_remove_recursive(nsim_sdev_ddir);