Skip to content

Commit 283e6f5

Browse files
rsa9000kuba-moo
authored andcommitted
net: wwan: make debugfs optional
Debugfs interface is optional for the regular modem use. Some distros and users will want to disable this feature for security or kernel size reasons. So add a configuration option that allows to completely disable the debugfs interface of the WWAN devices. A primary considered use case for this option was embedded firmwares. For example, in OpenWrt, you can not completely disable debugfs, as a lot of wireless stuff can only be configured and monitored with the debugfs knobs. At the same time, reducing the size of a kernel and modules is an essential task in the world of embedded software. Disabling the WWAN and IOSM debugfs interfaces allows us to save 50K (x86-64 build) of space for module storage. Not much, but already considerable when you only have 16MB of storage. So it is hard to just disable whole debugfs. Users need some fine grained set of options to control which debugfs interface is important and should be available and which is not. The new configuration symbol is enabled by default and is hidden under the EXPERT option. So a regular user would not be bothered by another one configuration question. While an embedded distro maintainer will be able to a little more reduce the final image size. Signed-off-by: Sergey Ryazanov <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Reviewed-by: Loic Poulain <[email protected]> Acked-by: M Chetan Kumar <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent cf90098 commit 283e6f5

File tree

9 files changed

+68
-10
lines changed

9 files changed

+68
-10
lines changed

drivers/net/wwan/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ config WWAN
1616

1717
if WWAN
1818

19+
config WWAN_DEBUGFS
20+
bool "WWAN devices debugfs interface" if EXPERT
21+
depends on DEBUG_FS
22+
default y
23+
help
24+
Enables debugfs infrastructure for the WWAN core and device drivers.
25+
26+
If this option is selected, then you can find the debug interface
27+
elements for each WWAN device in a directory that is corresponding to
28+
the device name: debugfs/wwan/wwanX.
29+
1930
config WWAN_HWSIM
2031
tristate "Simulated WWAN device"
2132
help
@@ -85,7 +96,7 @@ config IOSM
8596
tristate "IOSM Driver for Intel M.2 WWAN Device"
8697
depends on INTEL_IOMMU
8798
select NET_DEVLINK
88-
select RELAY
99+
select RELAY if WWAN_DEBUGFS
89100
help
90101
This driver enables Intel M.2 WWAN Device communication.
91102

drivers/net/wwan/iosm/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ iosm-y = \
2121
iosm_ipc_mux_codec.o \
2222
iosm_ipc_devlink.o \
2323
iosm_ipc_flash.o \
24-
iosm_ipc_coredump.o \
24+
iosm_ipc_coredump.o
25+
26+
iosm-$(CONFIG_WWAN_DEBUGFS) += \
2527
iosm_ipc_debugfs.o \
2628
iosm_ipc_trace.o
2729

drivers/net/wwan/iosm/iosm_ipc_debugfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
#ifndef IOSM_IPC_DEBUGFS_H
77
#define IOSM_IPC_DEBUGFS_H
88

9+
#ifdef CONFIG_WWAN_DEBUGFS
910
void ipc_debugfs_init(struct iosm_imem *ipc_imem);
1011
void ipc_debugfs_deinit(struct iosm_imem *ipc_imem);
12+
#else
13+
static inline void ipc_debugfs_init(struct iosm_imem *ipc_imem) {}
14+
static inline void ipc_debugfs_deinit(struct iosm_imem *ipc_imem) {}
15+
#endif
1116

1217
#endif

drivers/net/wwan/iosm/iosm_ipc_imem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static void ipc_imem_dl_skb_process(struct iosm_imem *ipc_imem,
274274
ipc_imem_sys_devlink_notify_rx(ipc_imem->ipc_devlink,
275275
skb);
276276
else if (ipc_is_trace_channel(ipc_imem, port_id))
277-
ipc_trace_port_rx(ipc_imem->trace, skb);
277+
ipc_trace_port_rx(ipc_imem, skb);
278278
else
279279
wwan_port_rx(ipc_imem->ipc_port[port_id]->iosm_port,
280280
skb);

drivers/net/wwan/iosm/iosm_ipc_imem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ struct iosm_imem {
351351
struct iosm_mux *mux;
352352
struct iosm_cdev *ipc_port[IPC_MEM_MAX_CHANNELS];
353353
struct iosm_pcie *pcie;
354+
#ifdef CONFIG_WWAN_DEBUGFS
354355
struct iosm_trace *trace;
356+
#endif
355357
struct device *dev;
356358
enum ipc_mem_device_ipc_state ipc_requested_state;
357359
struct ipc_mem_channel channels[IPC_MEM_MAX_CHANNELS];
@@ -381,7 +383,9 @@ struct iosm_imem {
381383
ev_mux_net_transmit_pending:1,
382384
reset_det_n:1,
383385
pcie_wake_n:1;
386+
#ifdef CONFIG_WWAN_DEBUGFS
384387
struct dentry *debugfs_dir;
388+
#endif
385389
};
386390

387391
/**

drivers/net/wwan/iosm/iosm_ipc_trace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
/**
1919
* ipc_trace_port_rx - Receive trace packet from cp and write to relay buffer
20-
* @ipc_trace: Pointer to the ipc trace data-struct
20+
* @ipc_imem: Pointer to iosm_imem structure
2121
* @skb: Pointer to struct sk_buff
2222
*/
23-
void ipc_trace_port_rx(struct iosm_trace *ipc_trace, struct sk_buff *skb)
23+
void ipc_trace_port_rx(struct iosm_imem *ipc_imem, struct sk_buff *skb)
2424
{
25+
struct iosm_trace *ipc_trace = ipc_imem->trace;
26+
2527
if (ipc_trace->ipc_rchan)
2628
relay_write(ipc_trace->ipc_rchan, skb->data, skb->len);
2729

drivers/net/wwan/iosm/iosm_ipc_trace.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,30 @@ struct iosm_trace {
4545
enum trace_ctrl_mode mode;
4646
};
4747

48+
#ifdef CONFIG_WWAN_DEBUGFS
49+
4850
static inline bool ipc_is_trace_channel(struct iosm_imem *ipc_mem, u16 chl_id)
4951
{
5052
return ipc_mem->trace && ipc_mem->trace->chl_id == chl_id;
5153
}
5254

5355
struct iosm_trace *ipc_trace_init(struct iosm_imem *ipc_imem);
5456
void ipc_trace_deinit(struct iosm_trace *ipc_trace);
55-
void ipc_trace_port_rx(struct iosm_trace *ipc_trace, struct sk_buff *skb);
57+
void ipc_trace_port_rx(struct iosm_imem *ipc_imem, struct sk_buff *skb);
58+
59+
#else
60+
61+
static inline bool ipc_is_trace_channel(struct iosm_imem *ipc_mem, u16 chl_id)
62+
{
63+
return false;
64+
}
65+
66+
static inline void ipc_trace_port_rx(struct iosm_imem *ipc_imem,
67+
struct sk_buff *skb)
68+
{
69+
dev_kfree_skb(skb);
70+
}
71+
72+
#endif
73+
5674
#endif

drivers/net/wwan/wwan_core.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ struct wwan_device {
5050
atomic_t port_id;
5151
const struct wwan_ops *ops;
5252
void *ops_ctxt;
53+
#ifdef CONFIG_WWAN_DEBUGFS
5354
struct dentry *debugfs_dir;
55+
#endif
5456
};
5557

5658
/**
@@ -146,6 +148,7 @@ static struct wwan_device *wwan_dev_get_by_name(const char *name)
146148
return to_wwan_dev(dev);
147149
}
148150

151+
#ifdef CONFIG_WWAN_DEBUGFS
149152
struct dentry *wwan_get_debugfs_dir(struct device *parent)
150153
{
151154
struct wwan_device *wwandev;
@@ -157,6 +160,7 @@ struct dentry *wwan_get_debugfs_dir(struct device *parent)
157160
return wwandev->debugfs_dir;
158161
}
159162
EXPORT_SYMBOL_GPL(wwan_get_debugfs_dir);
163+
#endif
160164

161165
/* This function allocates and registers a new WWAN device OR if a WWAN device
162166
* already exist for the given parent, it gets a reference and return it.
@@ -166,7 +170,6 @@ EXPORT_SYMBOL_GPL(wwan_get_debugfs_dir);
166170
static struct wwan_device *wwan_create_dev(struct device *parent)
167171
{
168172
struct wwan_device *wwandev;
169-
const char *wwandev_name;
170173
int err, id;
171174

172175
/* The 'find-alloc-register' operation must be protected against
@@ -206,9 +209,11 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
206209
goto done_unlock;
207210
}
208211

209-
wwandev_name = kobject_name(&wwandev->dev.kobj);
210-
wwandev->debugfs_dir = debugfs_create_dir(wwandev_name,
211-
wwan_debugfs_dir);
212+
#ifdef CONFIG_WWAN_DEBUGFS
213+
wwandev->debugfs_dir =
214+
debugfs_create_dir(kobject_name(&wwandev->dev.kobj),
215+
wwan_debugfs_dir);
216+
#endif
212217

213218
done_unlock:
214219
mutex_unlock(&wwan_register_lock);
@@ -240,7 +245,9 @@ static void wwan_remove_dev(struct wwan_device *wwandev)
240245
ret = device_for_each_child(&wwandev->dev, NULL, is_wwan_child);
241246

242247
if (!ret) {
248+
#ifdef CONFIG_WWAN_DEBUGFS
243249
debugfs_remove_recursive(wwandev->debugfs_dir);
250+
#endif
244251
device_unregister(&wwandev->dev);
245252
} else {
246253
put_device(&wwandev->dev);
@@ -1140,7 +1147,9 @@ static int __init wwan_init(void)
11401147
goto destroy;
11411148
}
11421149

1150+
#ifdef CONFIG_WWAN_DEBUGFS
11431151
wwan_debugfs_dir = debugfs_create_dir("wwan", NULL);
1152+
#endif
11441153

11451154
return 0;
11461155

include/linux/wwan.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops,
171171

172172
void wwan_unregister_ops(struct device *parent);
173173

174+
#ifdef CONFIG_WWAN_DEBUGFS
174175
struct dentry *wwan_get_debugfs_dir(struct device *parent);
176+
#else
177+
static inline struct dentry *wwan_get_debugfs_dir(struct device *parent)
178+
{
179+
return ERR_PTR(-ENODEV);
180+
}
181+
#endif
175182

176183
#endif /* __WWAN_H */

0 commit comments

Comments
 (0)