Skip to content

Commit

Permalink
ipack: save carrier owner to allow device to get it
Browse files Browse the repository at this point in the history
There was not any kind of protection against carrier driver removal.
In this way, device driver can 'get' the carrier driver when it is
using it.

Signed-off-by: Federico Vaga <[email protected]>
Acked-by: Samuel Iglesias Gonsalvez <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Federico Vaga authored and gregkh committed Sep 24, 2014
1 parent 78f22bc commit 36c53b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion drivers/ipack/carriers/tpci200.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
/* Register the carrier in the industry pack bus driver */
tpci200->info->ipack_bus = ipack_bus_register(&pdev->dev,
TPCI200_NB_SLOT,
&tpci200_bus_ops);
&tpci200_bus_ops,
THIS_MODULE);
if (!tpci200->info->ipack_bus) {
dev_err(&pdev->dev,
"error registering the carrier on ipack driver\n");
Expand Down
4 changes: 3 additions & 1 deletion drivers/ipack/ipack.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ static struct bus_type ipack_bus_type = {
};

struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
const struct ipack_bus_ops *ops)
const struct ipack_bus_ops *ops,
struct module *owner)
{
int bus_nr;
struct ipack_bus_device *bus;
Expand All @@ -225,6 +226,7 @@ struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
bus->parent = parent;
bus->slots = slots;
bus->ops = ops;
bus->owner = owner;
return bus;
}
EXPORT_SYMBOL_GPL(ipack_bus_register);
Expand Down
24 changes: 23 additions & 1 deletion include/linux/ipack.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ struct ipack_bus_ops {
* @ops: bus operations for the mezzanine drivers
*/
struct ipack_bus_device {
struct module *owner;
struct device *parent;
int slots;
int bus_nr;
Expand All @@ -189,7 +190,8 @@ struct ipack_bus_device {
* available bus device in ipack.
*/
struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
const struct ipack_bus_ops *ops);
const struct ipack_bus_ops *ops,
struct module *owner);

/**
* ipack_bus_unregister -- unregister an ipack bus
Expand Down Expand Up @@ -265,3 +267,23 @@ void ipack_put_device(struct ipack_device *dev);
.format = (_format), \
.vendor = (vend), \
.device = (dev)

/**
* ipack_get_carrier - it increase the carrier ref. counter of
* the carrier module
* @dev: mezzanine device which wants to get the carrier
*/
static inline int ipack_get_carrier(struct ipack_device *dev)
{
return try_module_get(dev->bus->owner);
}

/**
* ipack_get_carrier - it decrease the carrier ref. counter of
* the carrier module
* @dev: mezzanine device which wants to get the carrier
*/
static inline void ipack_put_carrier(struct ipack_device *dev)
{
module_put(dev->bus->owner);
}

0 comments on commit 36c53b3

Please sign in to comment.