aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kobject_uevent.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2017-09-13 19:29:48 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-09-18 10:48:33 -0400
commit6878e7de6af726de47f9f3bec649c3f49e786586 (patch)
tree50f2bc55120a88d9891866526c5a56ebb2ac1898 /lib/kobject_uevent.c
parent2bd6bf03f4c1c59381d62c61d03f6cc3fe71f66e (diff)
driver core: suppress sending MODALIAS in UNBIND uevents
The current udev rules cause modules to be loaded on all device events save for "remove". With the introduction of KOBJ_BIND/KOBJ_UNBIND this causes issues, as driver modules that have devices bound to their drivers get immediately reloaded, and it appears to the user that module unloading doe snot work. The standard udev matching rule is foillowing: ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load $env{MODALIAS}" Given that MODALIAS data is not terribly useful for UNBIND event, let's zap it from the generated uevent environment until we get userspace updated with the correct udev rule that only loads modules on "add" event. Reported-by: Jakub Kicinski <kubakici@wp.pl> Tested-by: Jakub Kicinski <kubakici@wp.pl> Fixes: 1455cf8dbfd0 ("driver core: emit uevents when device is bound ...") Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/kobject_uevent.c')
-rw-r--r--lib/kobject_uevent.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index e590523ea476..f237a09a5862 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -294,6 +294,26 @@ static void cleanup_uevent_env(struct subprocess_info *info)
294} 294}
295#endif 295#endif
296 296
297static void zap_modalias_env(struct kobj_uevent_env *env)
298{
299 static const char modalias_prefix[] = "MODALIAS=";
300 int i;
301
302 for (i = 0; i < env->envp_idx;) {
303 if (strncmp(env->envp[i], modalias_prefix,
304 sizeof(modalias_prefix) - 1)) {
305 i++;
306 continue;
307 }
308
309 if (i != env->envp_idx - 1)
310 memmove(&env->envp[i], &env->envp[i + 1],
311 sizeof(env->envp[i]) * env->envp_idx - 1);
312
313 env->envp_idx--;
314 }
315}
316
297/** 317/**
298 * kobject_uevent_env - send an uevent with environmental data 318 * kobject_uevent_env - send an uevent with environmental data
299 * 319 *
@@ -409,16 +429,29 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
409 } 429 }
410 } 430 }
411 431
412 /* 432 switch (action) {
413 * Mark "add" and "remove" events in the object to ensure proper 433 case KOBJ_ADD:
414 * events to userspace during automatic cleanup. If the object did 434 /*
415 * send an "add" event, "remove" will automatically generated by 435 * Mark "add" event so we can make sure we deliver "remove"
416 * the core, if not already done by the caller. 436 * event to userspace during automatic cleanup. If
417 */ 437 * the object did send an "add" event, "remove" will
418 if (action == KOBJ_ADD) 438 * automatically generated by the core, if not already done
439 * by the caller.
440 */
419 kobj->state_add_uevent_sent = 1; 441 kobj->state_add_uevent_sent = 1;
420 else if (action == KOBJ_REMOVE) 442 break;
443
444 case KOBJ_REMOVE:
421 kobj->state_remove_uevent_sent = 1; 445 kobj->state_remove_uevent_sent = 1;
446 break;
447
448 case KOBJ_UNBIND:
449 zap_modalias_env(env);
450 break;
451
452 default:
453 break;
454 }
422 455
423 mutex_lock(&uevent_sock_mutex); 456 mutex_lock(&uevent_sock_mutex);
424 /* we will send an event, so request a new sequence number */ 457 /* we will send an event, so request a new sequence number */