summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2020-10-15 14:52:45 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2020-10-15 14:52:45 -0700
commitca5387e448e1f88440dc93e143b353592f8a8af6 (patch)
tree545beddc17dc648d1c78c7e71589adea0a3ac201 /samples
parent5a32c3413d3340f90c82c84b375ad4b335a59f28 (diff)
parent76ecfcb0852eb0390881a695a2f349b804d80147 (diff)
downloadlwn-ca5387e448e1f88440dc93e143b353592f8a8af6.tar.gz
lwn-ca5387e448e1f88440dc93e143b353592f8a8af6.zip
Merge tag 'configfs-5.10' of git://git.infradead.org/users/hch/configfs
Pull configfs updates from Christoph Hellwig: "Various cleanups for the configfs samples (Bartosz Golaszewski)" * tag 'configfs-5.10' of git://git.infradead.org/users/hch/configfs: samples: configfs: prefer pr_err() over bare printk(KERN_ERR samples: configfs: don't use spaces before tabs samples: configfs: consolidate local variables of the same type samples: configfs: don't reinitialize variables which are already zeroed samples: configfs: replace simple_strtoul() with kstrtoint() samples: configfs: fix alignment in item struct samples: configfs: drop unnecessary ternary operators samples: configfs: remove redundant newlines MAINTAINERS: add the sample directory to the configfs entry
Diffstat (limited to 'samples')
-rw-r--r--samples/configfs/configfs_sample.c59
1 files changed, 19 insertions, 40 deletions
diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c
index e2398d94e8da..f9008be7a8a1 100644
--- a/samples/configfs/configfs_sample.c
+++ b/samples/configfs/configfs_sample.c
@@ -7,19 +7,17 @@
* macros defined by configfs.h
*
* Based on sysfs:
- * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
+ * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
*
* configfs Copyright (C) 2005 Oracle. All rights reserved.
*/
#include <linux/init.h>
+#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
-
#include <linux/configfs.h>
-
-
/*
* 01-childless
*
@@ -40,8 +38,8 @@ struct childless {
static inline struct childless *to_childless(struct config_item *item)
{
- return item ? container_of(to_configfs_subsystem(to_config_group(item)),
- struct childless, subsys) : NULL;
+ return container_of(to_configfs_subsystem(to_config_group(item)),
+ struct childless, subsys);
}
static ssize_t childless_showme_show(struct config_item *item, char *page)
@@ -64,17 +62,11 @@ static ssize_t childless_storeme_store(struct config_item *item,
const char *page, size_t count)
{
struct childless *childless = to_childless(item);
- unsigned long tmp;
- char *p = (char *) page;
-
- tmp = simple_strtoul(p, &p, 10);
- if (!p || (*p && (*p != '\n')))
- return -EINVAL;
-
- if (tmp > INT_MAX)
- return -ERANGE;
+ int ret;
- childless->storeme = tmp;
+ ret = kstrtoint(page, 10, &childless->storeme);
+ if (ret)
+ return ret;
return count;
}
@@ -117,7 +109,6 @@ static struct childless childless_subsys = {
},
};
-
/* ----------------------------------------------------------------- */
/*
@@ -136,7 +127,7 @@ struct simple_child {
static inline struct simple_child *to_simple_child(struct config_item *item)
{
- return item ? container_of(item, struct simple_child, item) : NULL;
+ return container_of(item, struct simple_child, item);
}
static ssize_t simple_child_storeme_show(struct config_item *item, char *page)
@@ -148,17 +139,11 @@ static ssize_t simple_child_storeme_store(struct config_item *item,
const char *page, size_t count)
{
struct simple_child *simple_child = to_simple_child(item);
- unsigned long tmp;
- char *p = (char *) page;
-
- tmp = simple_strtoul(p, &p, 10);
- if (!p || (*p && (*p != '\n')))
- return -EINVAL;
-
- if (tmp > INT_MAX)
- return -ERANGE;
+ int ret;
- simple_child->storeme = tmp;
+ ret = kstrtoint(page, 10, &simple_child->storeme);
+ if (ret)
+ return ret;
return count;
}
@@ -176,7 +161,7 @@ static void simple_child_release(struct config_item *item)
}
static struct configfs_item_operations simple_child_item_ops = {
- .release = simple_child_release,
+ .release = simple_child_release,
};
static const struct config_item_type simple_child_type = {
@@ -185,15 +170,14 @@ static const struct config_item_type simple_child_type = {
.ct_owner = THIS_MODULE,
};
-
struct simple_children {
struct config_group group;
};
static inline struct simple_children *to_simple_children(struct config_item *item)
{
- return item ? container_of(to_config_group(item),
- struct simple_children, group) : NULL;
+ return container_of(to_config_group(item),
+ struct simple_children, group);
}
static struct config_item *simple_children_make_item(struct config_group *group,
@@ -208,8 +192,6 @@ static struct config_item *simple_children_make_item(struct config_group *group,
config_item_init_type_name(&simple_child->item, name,
&simple_child_type);
- simple_child->storeme = 0;
-
return &simple_child->item;
}
@@ -263,7 +245,6 @@ static struct configfs_subsystem simple_children_subsys = {
},
};
-
/* ----------------------------------------------------------------- */
/*
@@ -350,9 +331,8 @@ static struct configfs_subsystem *example_subsys[] = {
static int __init configfs_example_init(void)
{
- int ret;
- int i;
struct configfs_subsystem *subsys;
+ int ret, i;
for (i = 0; example_subsys[i]; i++) {
subsys = example_subsys[i];
@@ -361,9 +341,8 @@ static int __init configfs_example_init(void)
mutex_init(&subsys->su_mutex);
ret = configfs_register_subsystem(subsys);
if (ret) {
- printk(KERN_ERR "Error %d while registering subsystem %s\n",
- ret,
- subsys->su_group.cg_item.ci_namebuf);
+ pr_err("Error %d while registering subsystem %s\n",
+ ret, subsys->su_group.cg_item.ci_namebuf);
goto out_unregister;
}
}