configfs updates for 5.10

- various cleanups for the configfs samples (Bartosz Golaszewski)
 -----BEGIN PGP SIGNATURE-----
 
 iQI/BAABCgApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAl+IjBILHGhjaEBsc3Qu
 ZGUACgkQD55TZVIEUYM0WxAAv9JzqdcGdPiPdhfJH/4PTigeo7gFcEaQEj3q1XSS
 hcrlsGwAoYZSFT/ZKVHfq8kZAMcRMvfhXZ2WLMmScPV+tFzsFtUP3+smQp9fsfBS
 Cg+HCnnwTQnj4zhzLSLMQcX28qt/aG5ssLr8eiD5JxJzNxx9mfV01w3FNBvWbWM7
 2ymaQXqdCbR4vRMPrmz8ukTHqCvsy2xbmIELTHx9Tnz1+jFT09S+qjSfL+p+iyQx
 +RbzB/Lq1N45TkIqM2NqAKEnwJdQ2rAnBJb+D75wrEgCyvoP5LD8npvPnAzLdtaT
 FN2p9I6ST06QEdxGyTJYKpshsTkcp/Qljs5EReeKjuqeGOR/gQKT4oHuvH2ph4OT
 x35iN7ErD+TGna0InitiRSMOxM1KFE9vsPGPUIcka8rpEvuOA6ZyXcT3ZnuupR5i
 ZGr+JRHLIMAdPimQ9MxsYupBVU8Fan1xMDyVoCDRWsHve+1qjzTafZmTQ8OmGGyK
 F+9js2RXuLr+OYUeBiGY+67yxboMuENOQdETCvhWUmHitI5piLFXQyTaUFTZX5yv
 NRty3Vw0ts5JywUR+xx7VgTKpbF5pLDEtMcJwcvoSV12ykq7oIQLezHMD0MtAu4N
 mWsyXWZHAGphL1GIRbGyKgLoWJVlAzfmg/s3xo+bHiuaw++mvrzqUx4y4NG9UjwH
 UCY=
 =+IRh
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2020-10-15 14:52:45 -07:00
commit ca5387e448
2 changed files with 20 additions and 40 deletions

View File

@ -4415,6 +4415,7 @@ S: Supported
T: git git://git.infradead.org/users/hch/configfs.git
F: fs/configfs/
F: include/linux/configfs.h
F: samples/configfs/
CONSOLE SUBSYSTEM
M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

View File

@ -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;
int ret;
tmp = simple_strtoul(p, &p, 10);
if (!p || (*p && (*p != '\n')))
return -EINVAL;
if (tmp > INT_MAX)
return -ERANGE;
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;
int ret;
tmp = simple_strtoul(p, &p, 10);
if (!p || (*p && (*p != '\n')))
return -EINVAL;
if (tmp > INT_MAX)
return -ERANGE;
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;
}
}