From: Borislav Petkov <bp@alien8.de>
To: Aaron Williams <Aaron.Williams@cavium.com>
Cc: linux-kernel@vger.kernel.org, "Williams,
Aaron" <Aaron.Williams@caviumnetworks.com>
Subject: Re: Incrementing module reference count
Date: Sat, 8 Dec 2012 12:44:53 +0100 [thread overview]
Message-ID: <20121208114453.GC11662@liondog.tnic> (raw)
In-Reply-To: <50C2947F.5030706@cavium.com>
On Fri, Dec 07, 2012 at 05:14:39PM -0800, Aaron Williams wrote:
> Hi,
>
> I have a kernel module which other modules register with in order to
> export access functions. So far I have everything working but I want
> to prevent a module that is registered with my module from unloading
> since now my module is dependent on the other module.
>
> Is there a way I can cause the reference count of the module
> registering with my module to increase? I tried calling get_device
> with the device structure of the module that is registering but that
> does not seem to work.
>
> For example, I have the following function:
>
> /**
> * Adds a mapping of a device node to a memory accessor
> *
> * @param[in] dev - device
> * @param[in] macc - memory accessor
> *
> * @returns 0 for success or -ENOMEM
> */
> int of_memory_accessor_register(struct device *dev,
> struct memory_accessor *macc)
> {
> struct of_macc_entry *mentry;
>
> mentry = kmalloc(sizeof(*mentry), GFP_KERNEL);
> if (mentry == NULL)
> return -ENOMEM;
>
> mentry->dev = dev;
> mentry->macc = macc;
>
> mutex_lock(&lock);
>
> get_device(dev);
> list_add(&(mentry->list), &macc_list);
>
> mutex_unlock(&lock);
>
> return 0;
> }
> EXPORT_SYMBOL(of_memory_accessor_register);
>
> Basically my module is used for things like serial EEPROMs and
> whatnot so that external modules can find the accessor functions
> based on the device tree. In my case I am updating the Vitesse
> VSC848X driver so that it can read the SFP module when it is plugged
> in using the AT24 I2C EEPROM module. I want to prevent the at24
> module from unloading while other modules in turn are using it. The
> at24 module does not export any symbols.
>From a quick code scan, at24 has this:
static struct i2c_driver at24_driver = {
.driver = {
.name = "at24",
.owner = THIS_MODULE,
},
.probe = at24_probe,
.remove = __devexit_p(at24_remove),
.id_table = at24_ids,
};
and then you could do:
try_module_get(at24_driver.driver->owner);
from your code. AFAICT, of course.
HTH.
--
Regards/Gruss,
Boris.
next prev parent reply other threads:[~2012-12-08 11:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-08 1:14 Aaron Williams
2012-12-08 11:44 ` Borislav Petkov [this message]
2012-12-08 19:17 ` Aaron Williams
2012-12-09 11:55 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121208114453.GC11662@liondog.tnic \
--to=bp@alien8.de \
--cc=Aaron.Williams@cavium.com \
--cc=Aaron.Williams@caviumnetworks.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®