Skip to content

Commit

Permalink
samples: configfs: drop unnecessary ternary operators
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
brgl authored and Christoph Hellwig committed Oct 7, 2020
1 parent 4472437 commit e0ee1fd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions samples/configfs/configfs_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e0ee1fd

Please sign in to comment.