* [PATCH] modprobe: use flags rather than bool args
@ 2019-11-07 7:38 Lucas De Marchi
2019-11-07 9:30 ` Yauheni Kaliuta
0 siblings, 1 reply; 2+ messages in thread
From: Lucas De Marchi @ 2019-11-07 7:38 UTC (permalink / raw)
To: linux-modules; +Cc: Yauheni Kaliuta
It's easier to know what the caller is doing when we pass a named
flag rather than a list of bools.
---
tools/modprobe.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/modprobe.c b/tools/modprobe.c
index 44cd15c..9387537 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -353,8 +353,9 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
return err;
}
-static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
- bool ignore_builtin);
+#define RMMOD_FLAG_DO_DEPENDENCIES 0x1
+#define RMMOD_FLAG_IGNORE_BUILTIN 0x2
+static int rmmod_do_module(struct kmod_module *mod, int flags);
static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
{
@@ -362,7 +363,7 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
kmod_list_foreach_reverse(l, list) {
struct kmod_module *m = kmod_module_get_module(l);
- int r = rmmod_do_module(m, false, true);
+ int r = rmmod_do_module(m, RMMOD_FLAG_IGNORE_BUILTIN);
kmod_module_unref(m);
if (r < 0 && stop_on_errors)
@@ -372,8 +373,7 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
return 0;
}
-static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
- bool ignore_builtin)
+static int rmmod_do_module(struct kmod_module *mod, int flags)
{
const char *modname = kmod_module_get_name(mod);
struct kmod_list *pre = NULL, *post = NULL;
@@ -403,7 +403,7 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
}
goto error;
} else if (state == KMOD_MODULE_BUILTIN) {
- if (ignore_builtin) {
+ if (flags & RMMOD_FLAG_IGNORE_BUILTIN) {
err = 0;
} else {
LOG("Module %s is builtin.\n", modname);
@@ -415,7 +415,7 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
rmmod_do_deps_list(post, false);
- if (do_dependencies && remove_dependencies) {
+ if ((flags & RMMOD_FLAG_DO_DEPENDENCIES) && remove_dependencies) {
struct kmod_list *deps = kmod_module_get_dependencies(mod);
err = rmmod_do_deps_list(deps, true);
@@ -468,7 +468,7 @@ static int rmmod(struct kmod_ctx *ctx, const char *alias)
kmod_list_foreach(l, list) {
struct kmod_module *mod = kmod_module_get_module(l);
- err = rmmod_do_module(mod, true, false);
+ err = rmmod_do_module(mod, RMMOD_FLAG_DO_DEPENDENCIES);
kmod_module_unref(mod);
if (err < 0)
break;
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] modprobe: use flags rather than bool args
2019-11-07 7:38 [PATCH] modprobe: use flags rather than bool args Lucas De Marchi
@ 2019-11-07 9:30 ` Yauheni Kaliuta
0 siblings, 0 replies; 2+ messages in thread
From: Yauheni Kaliuta @ 2019-11-07 9:30 UTC (permalink / raw)
To: Lucas De Marchi; +Cc: linux-modules
Hi, Lucas!
>>>>> On Wed, 6 Nov 2019 23:38:57 -0800, Lucas De Marchi wrote:
> It's easier to know what the caller is doing when we pass a named
> flag rather than a list of bools.
Yeah, it's much better, thanks!
> ---
> tools/modprobe.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
> diff --git a/tools/modprobe.c b/tools/modprobe.c
> index 44cd15c..9387537 100644
> --- a/tools/modprobe.c
> +++ b/tools/modprobe.c
> @@ -353,8 +353,9 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
> return err;
> }
> -static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
> - bool ignore_builtin);
> +#define RMMOD_FLAG_DO_DEPENDENCIES 0x1
> +#define RMMOD_FLAG_IGNORE_BUILTIN 0x2
> +static int rmmod_do_module(struct kmod_module *mod, int flags);
> static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
> {
> @@ -362,7 +363,7 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
> kmod_list_foreach_reverse(l, list) {
> struct kmod_module *m = kmod_module_get_module(l);
> - int r = rmmod_do_module(m, false, true);
> + int r = rmmod_do_module(m, RMMOD_FLAG_IGNORE_BUILTIN);
> kmod_module_unref(m);
> if (r < 0 && stop_on_errors)
> @@ -372,8 +373,7 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
> return 0;
> }
> -static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
> - bool ignore_builtin)
> +static int rmmod_do_module(struct kmod_module *mod, int flags)
> {
> const char *modname = kmod_module_get_name(mod);
> struct kmod_list *pre = NULL, *post = NULL;
> @@ -403,7 +403,7 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
> }
> goto error;
> } else if (state == KMOD_MODULE_BUILTIN) {
> - if (ignore_builtin) {
> + if (flags & RMMOD_FLAG_IGNORE_BUILTIN) {
> err = 0;
> } else {
> LOG("Module %s is builtin.\n", modname);
> @@ -415,7 +415,7 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
> rmmod_do_deps_list(post, false);
> - if (do_dependencies && remove_dependencies) {
> + if ((flags & RMMOD_FLAG_DO_DEPENDENCIES) && remove_dependencies) {
> struct kmod_list *deps = kmod_module_get_dependencies(mod);
> err = rmmod_do_deps_list(deps, true);
> @@ -468,7 +468,7 @@ static int rmmod(struct kmod_ctx *ctx, const char *alias)
> kmod_list_foreach(l, list) {
> struct kmod_module *mod = kmod_module_get_module(l);
> - err = rmmod_do_module(mod, true, false);
> + err = rmmod_do_module(mod, RMMOD_FLAG_DO_DEPENDENCIES);
> kmod_module_unref(mod);
> if (err < 0)
> break;
> --
> 2.24.0
--
WBR,
Yauheni Kaliuta
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-07 9:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 7:38 [PATCH] modprobe: use flags rather than bool args Lucas De Marchi
2019-11-07 9:30 ` Yauheni Kaliuta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).