<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 16, 2014 at 9:51 PM, Greg KH <span dir="ltr"><<a href="mailto:greg@kroah.com" target="_blank">greg@kroah.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, Jul 16, 2014 at 08:57:38PM +0530, Chetan Nanda wrote:<br>
><br>
><br>
><br>
> On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda <<a href="mailto:chetannanda@gmail.com">chetannanda@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza <<a href="mailto:john@jjdev.com">john@jjdev.com</a>> wrote:<br>
><br>
> On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda wrote:<br>
> > A depends on B, so B is automatically loaded when A is loaded.<br>
> > B module is also directly being used by the user side code via misc<br>
> > interface.<br>
> >.<br>
> > Now when I am unloading module A, via "modprobe -r A" it is also<br>
> unloading<br>
> > the module B which is being used by the application and resulting in<br>
> the<br>
> > kernel crash.<br>
><br>
> You said that A depends on B, right? Why do you have A dependng on B?<br>
> If it A needs to have B then it makes sense that you can not remove A<br>
> while<br>
> B is in use. If A doesn't need B, why not remove the dependency.<br>
><br>
> <br>
> A is calling few APIs defined by B. <br>
><br>
> But why when user space application is already using module B. (it has already<br>
> open its device fd) kernel allows to remove it.<br>
><br>
> I tried with doing try_module_get() in the module's open function, it prevent<br>
> module B unloading but cause thread doing modprobe -r to hang<br>
> Is there any other way to mark module as busy when being used by user<br>
> application?<br>
<br>
</div></div>Never use try_module_get(), that is racy.<br>
<br>
What is the user/kernel interface you are using, and why doesn't it<br>
automatically increase the module count when userspace opens the<br>
interface? It should all be done in a way that your module doesn't need<br>
to do anything special.<br>
<br></blockquote><div>Hi Greg, </div><div><br></div><div>Thanks for your mail.</div><div> </div><div>Module is using misc driver interface to export its functionality to userspace, </div><div><br></div><div>Need to debug further why module count is not getting incremented automatically when module is open by userspace application via open system call.</div>
<div> </div><div>Thanks</div><div>Chetan Nanda</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
thanks,<br>
<br>
greg k-h<br>
<br>
</blockquote></div><br></div></div>