Skip to content

Commit 3bcacd1

Browse files
gregkhsimonwunderlich
authored andcommitted
batman-adv: no need to check return value of debugfs_create functions
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this. Because we don't care if debugfs works or not, this trickles back a bit so we can clean things up by making some functions return void instead of an error value that is never going to fail. Cc: Marek Lindner <[email protected]> Cc: Simon Wunderlich <[email protected]> Cc: Antonio Quartulli <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> [[email protected]: drop unused variables] Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent 390dcd4 commit 3bcacd1

File tree

8 files changed

+39
-144
lines changed

8 files changed

+39
-144
lines changed

net/batman-adv/debugfs.c

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <asm/current.h>
1111
#include <linux/dcache.h>
1212
#include <linux/debugfs.h>
13-
#include <linux/err.h>
1413
#include <linux/errno.h>
1514
#include <linux/export.h>
1615
#include <linux/fs.h>
@@ -293,31 +292,13 @@ static struct batadv_debuginfo *batadv_hardif_debuginfos[] = {
293292
void batadv_debugfs_init(void)
294293
{
295294
struct batadv_debuginfo **bat_debug;
296-
struct dentry *file;
297295

298296
batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
299-
if (batadv_debugfs == ERR_PTR(-ENODEV))
300-
batadv_debugfs = NULL;
301-
302-
if (!batadv_debugfs)
303-
goto err;
304-
305-
for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
306-
file = debugfs_create_file(((*bat_debug)->attr).name,
307-
S_IFREG | ((*bat_debug)->attr).mode,
308-
batadv_debugfs, NULL,
309-
&(*bat_debug)->fops);
310-
if (!file) {
311-
pr_err("Can't add general debugfs file: %s\n",
312-
((*bat_debug)->attr).name);
313-
goto err;
314-
}
315-
}
316297

317-
return;
318-
err:
319-
debugfs_remove_recursive(batadv_debugfs);
320-
batadv_debugfs = NULL;
298+
for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug)
299+
debugfs_create_file(((*bat_debug)->attr).name,
300+
S_IFREG | ((*bat_debug)->attr).mode,
301+
batadv_debugfs, NULL, &(*bat_debug)->fops);
321302
}
322303

323304
/**
@@ -333,42 +314,23 @@ void batadv_debugfs_destroy(void)
333314
* batadv_debugfs_add_hardif() - creates the base directory for a hard interface
334315
* in debugfs.
335316
* @hard_iface: hard interface which should be added.
336-
*
337-
* Return: 0 on success or negative error number in case of failure
338317
*/
339-
int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
318+
void batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
340319
{
341320
struct net *net = dev_net(hard_iface->net_dev);
342321
struct batadv_debuginfo **bat_debug;
343-
struct dentry *file;
344-
345-
if (!batadv_debugfs)
346-
goto out;
347322

348323
if (net != &init_net)
349-
return 0;
324+
return;
350325

351326
hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name,
352327
batadv_debugfs);
353-
if (!hard_iface->debug_dir)
354-
goto out;
355-
356-
for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) {
357-
file = debugfs_create_file(((*bat_debug)->attr).name,
358-
S_IFREG | ((*bat_debug)->attr).mode,
359-
hard_iface->debug_dir,
360-
hard_iface->net_dev,
361-
&(*bat_debug)->fops);
362-
if (!file)
363-
goto rem_attr;
364-
}
365328

366-
return 0;
367-
rem_attr:
368-
debugfs_remove_recursive(hard_iface->debug_dir);
369-
hard_iface->debug_dir = NULL;
370-
out:
371-
return -ENOMEM;
329+
for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug)
330+
debugfs_create_file(((*bat_debug)->attr).name,
331+
S_IFREG | ((*bat_debug)->attr).mode,
332+
hard_iface->debug_dir, hard_iface->net_dev,
333+
&(*bat_debug)->fops);
372334
}
373335

374336
/**
@@ -379,15 +341,12 @@ void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
379341
{
380342
const char *name = hard_iface->net_dev->name;
381343
struct dentry *dir;
382-
struct dentry *d;
383344

384345
dir = hard_iface->debug_dir;
385346
if (!dir)
386347
return;
387348

388-
d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
389-
if (!d)
390-
pr_err("Can't rename debugfs dir to %s\n", name);
349+
debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
391350
}
392351

393352
/**
@@ -419,44 +378,29 @@ int batadv_debugfs_add_meshif(struct net_device *dev)
419378
struct batadv_priv *bat_priv = netdev_priv(dev);
420379
struct batadv_debuginfo **bat_debug;
421380
struct net *net = dev_net(dev);
422-
struct dentry *file;
423-
424-
if (!batadv_debugfs)
425-
goto out;
426381

427382
if (net != &init_net)
428383
return 0;
429384

430385
bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
431-
if (!bat_priv->debug_dir)
432-
goto out;
433386

434-
if (batadv_socket_setup(bat_priv) < 0)
435-
goto rem_attr;
387+
batadv_socket_setup(bat_priv);
436388

437389
if (batadv_debug_log_setup(bat_priv) < 0)
438390
goto rem_attr;
439391

440-
for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
441-
file = debugfs_create_file(((*bat_debug)->attr).name,
442-
S_IFREG | ((*bat_debug)->attr).mode,
443-
bat_priv->debug_dir,
444-
dev, &(*bat_debug)->fops);
445-
if (!file) {
446-
batadv_err(dev, "Can't add debugfs file: %s/%s\n",
447-
dev->name, ((*bat_debug)->attr).name);
448-
goto rem_attr;
449-
}
450-
}
392+
for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug)
393+
debugfs_create_file(((*bat_debug)->attr).name,
394+
S_IFREG | ((*bat_debug)->attr).mode,
395+
bat_priv->debug_dir, dev,
396+
&(*bat_debug)->fops);
451397

452-
if (batadv_nc_init_debugfs(bat_priv) < 0)
453-
goto rem_attr;
398+
batadv_nc_init_debugfs(bat_priv);
454399

455400
return 0;
456401
rem_attr:
457402
debugfs_remove_recursive(bat_priv->debug_dir);
458403
bat_priv->debug_dir = NULL;
459-
out:
460404
return -ENOMEM;
461405
}
462406

@@ -469,15 +413,12 @@ void batadv_debugfs_rename_meshif(struct net_device *dev)
469413
struct batadv_priv *bat_priv = netdev_priv(dev);
470414
const char *name = dev->name;
471415
struct dentry *dir;
472-
struct dentry *d;
473416

474417
dir = bat_priv->debug_dir;
475418
if (!dir)
476419
return;
477420

478-
d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
479-
if (!d)
480-
pr_err("Can't rename debugfs dir to %s\n", name);
421+
debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
481422
}
482423

483424
/**

net/batman-adv/debugfs.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void batadv_debugfs_destroy(void);
2222
int batadv_debugfs_add_meshif(struct net_device *dev);
2323
void batadv_debugfs_rename_meshif(struct net_device *dev);
2424
void batadv_debugfs_del_meshif(struct net_device *dev);
25-
int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface);
25+
void batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface);
2626
void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface);
2727
void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface);
2828

@@ -54,9 +54,8 @@ static inline void batadv_debugfs_del_meshif(struct net_device *dev)
5454
}
5555

5656
static inline
57-
int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
57+
void batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
5858
{
59-
return 0;
6059
}
6160

6261
static inline

net/batman-adv/hard-interface.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
921921
hard_iface->soft_iface = NULL;
922922
hard_iface->if_status = BATADV_IF_NOT_IN_USE;
923923

924-
ret = batadv_debugfs_add_hardif(hard_iface);
925-
if (ret)
926-
goto free_sysfs;
924+
batadv_debugfs_add_hardif(hard_iface);
927925

928926
INIT_LIST_HEAD(&hard_iface->list);
929927
INIT_HLIST_HEAD(&hard_iface->neigh_list);
@@ -945,8 +943,6 @@ batadv_hardif_add_interface(struct net_device *net_dev)
945943

946944
return hard_iface;
947945

948-
free_sysfs:
949-
batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
950946
free_if:
951947
kfree(hard_iface);
952948
release_dev:

net/batman-adv/icmp_socket.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,11 @@ static const struct file_operations batadv_fops = {
314314
/**
315315
* batadv_socket_setup() - Create debugfs "socket" file
316316
* @bat_priv: the bat priv with all the soft interface information
317-
*
318-
* Return: 0 on success or negative error number in case of failure
319317
*/
320-
int batadv_socket_setup(struct batadv_priv *bat_priv)
318+
void batadv_socket_setup(struct batadv_priv *bat_priv)
321319
{
322-
struct dentry *d;
323-
324-
if (!bat_priv->debug_dir)
325-
goto err;
326-
327-
d = debugfs_create_file(BATADV_ICMP_SOCKET, 0600, bat_priv->debug_dir,
328-
bat_priv, &batadv_fops);
329-
if (!d)
330-
goto err;
331-
332-
return 0;
333-
334-
err:
335-
return -ENOMEM;
320+
debugfs_create_file(BATADV_ICMP_SOCKET, 0600, bat_priv->debug_dir,
321+
bat_priv, &batadv_fops);
336322
}
337323

338324
/**

net/batman-adv/icmp_socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#define BATADV_ICMP_SOCKET "socket"
1616

17-
int batadv_socket_setup(struct batadv_priv *bat_priv);
17+
void batadv_socket_setup(struct batadv_priv *bat_priv);
1818

1919
#ifdef CONFIG_BATMAN_ADV_DEBUGFS
2020

net/batman-adv/log.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,16 @@ static const struct file_operations batadv_log_fops = {
190190
*/
191191
int batadv_debug_log_setup(struct batadv_priv *bat_priv)
192192
{
193-
struct dentry *d;
194-
195-
if (!bat_priv->debug_dir)
196-
goto err;
197-
198193
bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
199194
if (!bat_priv->debug_log)
200-
goto err;
195+
return -ENOMEM;
201196

202197
spin_lock_init(&bat_priv->debug_log->lock);
203198
init_waitqueue_head(&bat_priv->debug_log->queue_wait);
204199

205-
d = debugfs_create_file("log", 0400, bat_priv->debug_dir, bat_priv,
206-
&batadv_log_fops);
207-
if (!d)
208-
goto err;
209-
200+
debugfs_create_file("log", 0400, bat_priv->debug_dir, bat_priv,
201+
&batadv_log_fops);
210202
return 0;
211-
212-
err:
213-
return -ENOMEM;
214203
}
215204

216205
/**

net/batman-adv/network-coding.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,34 +1951,19 @@ int batadv_nc_nodes_seq_print_text(struct seq_file *seq, void *offset)
19511951
/**
19521952
* batadv_nc_init_debugfs() - create nc folder and related files in debugfs
19531953
* @bat_priv: the bat priv with all the soft interface information
1954-
*
1955-
* Return: 0 on success or negative error number in case of failure
19561954
*/
1957-
int batadv_nc_init_debugfs(struct batadv_priv *bat_priv)
1955+
void batadv_nc_init_debugfs(struct batadv_priv *bat_priv)
19581956
{
1959-
struct dentry *nc_dir, *file;
1957+
struct dentry *nc_dir;
19601958

19611959
nc_dir = debugfs_create_dir("nc", bat_priv->debug_dir);
1962-
if (!nc_dir)
1963-
goto out;
19641960

1965-
file = debugfs_create_u8("min_tq", 0644, nc_dir, &bat_priv->nc.min_tq);
1966-
if (!file)
1967-
goto out;
1961+
debugfs_create_u8("min_tq", 0644, nc_dir, &bat_priv->nc.min_tq);
19681962

1969-
file = debugfs_create_u32("max_fwd_delay", 0644, nc_dir,
1970-
&bat_priv->nc.max_fwd_delay);
1971-
if (!file)
1972-
goto out;
1963+
debugfs_create_u32("max_fwd_delay", 0644, nc_dir,
1964+
&bat_priv->nc.max_fwd_delay);
19731965

1974-
file = debugfs_create_u32("max_buffer_time", 0644, nc_dir,
1975-
&bat_priv->nc.max_buffer_time);
1976-
if (!file)
1977-
goto out;
1978-
1979-
return 0;
1980-
1981-
out:
1982-
return -ENOMEM;
1966+
debugfs_create_u32("max_buffer_time", 0644, nc_dir,
1967+
&bat_priv->nc.max_buffer_time);
19831968
}
19841969
#endif

net/batman-adv/network-coding.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv,
3939
void batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv,
4040
struct sk_buff *skb);
4141
int batadv_nc_nodes_seq_print_text(struct seq_file *seq, void *offset);
42-
int batadv_nc_init_debugfs(struct batadv_priv *bat_priv);
42+
void batadv_nc_init_debugfs(struct batadv_priv *bat_priv);
4343

4444
#else /* ifdef CONFIG_BATMAN_ADV_NC */
4545

@@ -110,9 +110,8 @@ static inline int batadv_nc_nodes_seq_print_text(struct seq_file *seq,
110110
return 0;
111111
}
112112

113-
static inline int batadv_nc_init_debugfs(struct batadv_priv *bat_priv)
113+
static inline void batadv_nc_init_debugfs(struct batadv_priv *bat_priv)
114114
{
115-
return 0;
116115
}
117116

118117
#endif /* ifdef CONFIG_BATMAN_ADV_NC */

0 commit comments

Comments
 (0)