On Tue, 12 Jun 2018 11:06:15 +0300 Moni Shoua <monis@xxxxxxxxxxxx> wrote: > On Tue, Jun 12, 2018 at 10:35 AM Hannes Reinecke <hare@xxxxxxx> wrote: > > > > When using the module option 'add' during modprobe the module will > > crash as the option is evaluated before the module itself is > > initialized. So return an error when rxe_param_set_add() is called > > before the module is initialized. > > > > Signed-off-by: Hannes Reinecke <hare@xxxxxxxx> > > --- > > drivers/infiniband/sw/rxe/rxe.c | 6 ++++++ > > drivers/infiniband/sw/rxe/rxe.h | 2 ++ > > drivers/infiniband/sw/rxe/rxe_sysfs.c | 5 +++++ > > 3 files changed, 13 insertions(+) > > > > diff --git a/drivers/infiniband/sw/rxe/rxe.c > > b/drivers/infiniband/sw/rxe/rxe.c index 7121e1b1eb89..53279d82e5cc > > 100644 --- a/drivers/infiniband/sw/rxe/rxe.c > > +++ b/drivers/infiniband/sw/rxe/rxe.c > > @@ -39,6 +39,8 @@ MODULE_AUTHOR("Bob Pearson, Frank Zago, John > > Groves, Kamal Heib"); MODULE_DESCRIPTION("Soft RDMA transport"); > > MODULE_LICENSE("Dual BSD/GPL"); > > > > +bool rxe_init_done = false; > > + > > /* free resources for all ports on a device */ > > static void rxe_cleanup_ports(struct rxe_dev *rxe) > > { > > @@ -354,6 +356,8 @@ static int __init rxe_module_init(void) > > if (err) > > return err; > > > > + rxe_init_done = true; > > + > > pr_info("loaded\n"); > > return 0; > > } > > @@ -364,6 +368,8 @@ static void __exit rxe_module_exit(void) > > rxe_net_exit(); > > rxe_cache_exit(); > > > > + rxe_init_done = false; > why not earlier? Because it's impossible to call 'modprobe' while an 'rmmod' is running; they are serialized against each other so we can be sure the module is fully unloaded before modprobe is run again. > > + > > pr_info("unloaded\n"); > > } > > > > diff --git a/drivers/infiniband/sw/rxe/rxe.h > > b/drivers/infiniband/sw/rxe/rxe.h index d9ec2de68738..0cf68bc7aa01 > > 100644 --- a/drivers/infiniband/sw/rxe/rxe.h > > +++ b/drivers/infiniband/sw/rxe/rxe.h > > @@ -92,6 +92,8 @@ static inline u32 rxe_crc32(struct rxe_dev *rxe, > > return retval; > > } > > > > +extern bool rxe_init_done; > > + > > void rxe_set_mtu(struct rxe_dev *rxe, unsigned int dev_mtu); > > > > int rxe_add(struct rxe_dev *rxe, unsigned int mtu); > > diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c > > b/drivers/infiniband/sw/rxe/rxe_sysfs.c index > > d5ed7571128f..bb54992e3ff2 100644 --- > > a/drivers/infiniband/sw/rxe/rxe_sysfs.c +++ > > b/drivers/infiniband/sw/rxe/rxe_sysfs.c @@ -77,6 +77,11 @@ static > > int rxe_param_set_add(const char *val, const struct kernel_param > > *kp) struct net_device *ndev = NULL; struct rxe_dev *rxe; > > > > + if (!rxe_init_done) { > > + pr_err("add: module not initializes\n"); > > + err = -EINVAL; > I think that EAGAIN is better I don't mind. Will be resending the patch. Cheers, Hannes -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html