From 8964bd4ff6f01462c7bdbe3d1280cf59e6157980 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:15 +0200 Subject: MAINTAINERS: add the sample directory to the configfs entry Code samples for configfs don't have an explicit maintainer. Add the samples directory to the existing configfs entry in MAINTAINERS. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index d746519253c3..6bbe4cb67331 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4407,6 +4407,7 @@ S: Supported T: git git://git.infradead.org/users/hch/configfs.git F: fs/configfs/ F: include/linux/configfs.h +F: samples/configfs/ CONNECTOR M: Evgeniy Polyakov -- cgit v1.2.3 From 447243737c9d52d9c77fe0da0ed993903b64f28c Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 7 Oct 2020 15:43:56 +0200 Subject: samples: configfs: remove redundant newlines There's no need for suplemental newlines in the source file - especially since the examples are well divided with comments already. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index e2398d94e8da..cabe77ef05d5 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -15,11 +15,8 @@ #include #include #include - #include - - /* * 01-childless * @@ -117,7 +114,6 @@ static struct childless childless_subsys = { }, }; - /* ----------------------------------------------------------------- */ /* @@ -185,7 +181,6 @@ static const struct config_item_type simple_child_type = { .ct_owner = THIS_MODULE, }; - struct simple_children { struct config_group group; }; @@ -263,7 +258,6 @@ static struct configfs_subsystem simple_children_subsys = { }, }; - /* ----------------------------------------------------------------- */ /* -- cgit v1.2.3 From e0ee1fdb3fc49102e03c34527c5185b4761c7c8f Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:18 +0200 Subject: samples: configfs: drop unnecessary ternary operators Checking pointers for NULL value before passing them to container_of() is pointless because even if we return NULL from the ternary operator, none of the users checks the returned value but they instead dereference it unconditionally. AFAICT this cannot really happen either. Simplify the code by removing the ternary operators from to_childless() et al. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index cabe77ef05d5..ad3f8e1071fa 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -37,8 +37,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) @@ -132,7 +132,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) @@ -187,8 +187,8 @@ struct simple_children { 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, -- cgit v1.2.3 From 1b0d36e81bdc52684af19f0cad9c9dca13ce4dbc Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:20 +0200 Subject: samples: configfs: fix alignment in item struct Aling the assignment of a static structure's field to be consistent with all other instances. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index ad3f8e1071fa..1af7cc965098 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -172,7 +172,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 = { -- cgit v1.2.3 From b86ff67d5a28f3ac1479d99b8a687e7107c58ae6 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:21 +0200 Subject: samples: configfs: replace simple_strtoul() with kstrtoint() simple_strtoul() is deprecated. Use kstrtoint(). Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index 1af7cc965098..7cf1d44c1e37 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -61,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; } @@ -144,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; } -- cgit v1.2.3 From 91aad62560fc8cc11a1f04e627da0c0f0d33ef08 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:22 +0200 Subject: samples: configfs: don't reinitialize variables which are already zeroed The structure containing the storeme field is allocated using kzalloc(). There's no need to set it to 0 again. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index 7cf1d44c1e37..66bb9bc5c8d0 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -192,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; } -- cgit v1.2.3 From 4e415a844ddd705cc7de87e01f0e6189a3def8ef Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:24 +0200 Subject: samples: configfs: consolidate local variables of the same type Move local variables of the same type into a single line for better readability. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index 66bb9bc5c8d0..2e56d6920642 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -331,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]; -- cgit v1.2.3 From 288f295e0a49481c4ff64715b6b3eb8ebfe3432b Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:25 +0200 Subject: samples: configfs: don't use spaces before tabs The copyright notice alarms checkpatch.pl of usin spaces before tabs. Fix this. Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index 2e56d6920642..83e2ad7a1b08 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -7,7 +7,7 @@ * 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. */ -- cgit v1.2.3 From 76ecfcb0852eb0390881a695a2f349b804d80147 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 24 Sep 2020 14:45:26 +0200 Subject: samples: configfs: prefer pr_err() over bare printk(KERN_ERR pr_*() printing helpers are preferred over using bare printk(). Signed-off-by: Bartosz Golaszewski Signed-off-by: Christoph Hellwig --- samples/configfs/configfs_sample.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index 83e2ad7a1b08..f9008be7a8a1 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -341,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; } } -- cgit v1.2.3