Commit 1e91795c authored by Jens Taprogge's avatar Jens Taprogge Committed by Greg Kroah-Hartman

Staging: ipack: Make ipack_device_register() analogous to device_register().

ipack_device_register() is no longer creating the struct ipack_device
but only registering it.  Instead of releasing memory directly the new
ipack_device->release callback is called.

This is preparational work for later patches.
Signed-off-by: default avatarJens Taprogge <jens.taprogge@taprogge.org>
Signed-off-by: default avatarSamuel Iglesias Gonsalvez <siglesias@igalia.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f9e314d2
...@@ -640,6 +640,23 @@ static int tpci200_install(struct tpci200_board *tpci200) ...@@ -640,6 +640,23 @@ static int tpci200_install(struct tpci200_board *tpci200)
return 0; return 0;
} }
static void tpci200_release_device(struct ipack_device *dev)
{
kfree(dev);
}
static int tpci200_create_device(struct tpci200_board *tpci200, int i)
{
struct ipack_device *dev =
kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
if (!dev)
return -ENOMEM;
dev->slot = i;
dev->bus = tpci200->info->ipack_bus;
dev->release = tpci200_release_device;
return ipack_device_register(dev);
}
static int tpci200_pci_probe(struct pci_dev *pdev, static int tpci200_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
...@@ -715,7 +732,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev, ...@@ -715,7 +732,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
dev_set_drvdata(&pdev->dev, tpci200); dev_set_drvdata(&pdev->dev, tpci200);
for (i = 0; i < TPCI200_NB_SLOT; i++) for (i = 0; i < TPCI200_NB_SLOT; i++)
ipack_device_register(tpci200->info->ipack_bus, i); tpci200_create_device(tpci200, i);
return 0; return 0;
out_err_bus_register: out_err_bus_register:
......
...@@ -24,7 +24,7 @@ static void ipack_device_release(struct device *dev) ...@@ -24,7 +24,7 @@ static void ipack_device_release(struct device *dev)
{ {
struct ipack_device *device = to_ipack_dev(dev); struct ipack_device *device = to_ipack_dev(dev);
kfree(device->id); kfree(device->id);
kfree(device); device->release(device);
} }
static inline const struct ipack_device_id * static inline const struct ipack_device_id *
...@@ -426,51 +426,39 @@ static int ipack_device_read_id(struct ipack_device *dev) ...@@ -426,51 +426,39 @@ static int ipack_device_read_id(struct ipack_device *dev)
return ret; return ret;
} }
struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int ipack_device_register(struct ipack_device *dev)
int slot)
{ {
int ret; int ret;
struct ipack_device *dev;
dev = kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
if (!dev)
return NULL;
dev->dev.bus = &ipack_bus_type; dev->dev.bus = &ipack_bus_type;
dev->dev.release = ipack_device_release; dev->dev.release = ipack_device_release;
dev->dev.parent = bus->parent; dev->dev.parent = dev->bus->parent;
dev->slot = slot;
dev->bus = bus;
dev_set_name(&dev->dev, dev_set_name(&dev->dev,
"ipack-dev.%u.%u", dev->bus->bus_nr, dev->slot); "ipack-dev.%u.%u", dev->bus->bus_nr, dev->slot);
if (bus->ops->set_clockrate(dev, 8)) if (dev->bus->ops->set_clockrate(dev, 8))
dev_warn(&dev->dev, "failed to switch to 8 MHz operation for reading of device ID.\n"); dev_warn(&dev->dev, "failed to switch to 8 MHz operation for reading of device ID.\n");
if (bus->ops->reset_timeout(dev)) if (dev->bus->ops->reset_timeout(dev))
dev_warn(&dev->dev, "failed to reset potential timeout."); dev_warn(&dev->dev, "failed to reset potential timeout.");
ret = ipack_device_read_id(dev); ret = ipack_device_read_id(dev);
if (ret < 0) { if (ret < 0) {
dev_err(&dev->dev, "error reading device id section.\n"); dev_err(&dev->dev, "error reading device id section.\n");
kfree(dev); return ret;
return NULL;
} }
/* if the device supports 32 MHz operation, use it. */ /* if the device supports 32 MHz operation, use it. */
if (dev->speed_32mhz) { if (dev->speed_32mhz) {
ret = bus->ops->set_clockrate(dev, 32); ret = dev->bus->ops->set_clockrate(dev, 32);
if (ret < 0) if (ret < 0)
dev_err(&dev->dev, "failed to switch to 32 MHz operation.\n"); dev_err(&dev->dev, "failed to switch to 32 MHz operation.\n");
} }
ret = device_register(&dev->dev); ret = device_register(&dev->dev);
if (ret < 0) { if (ret < 0)
kfree(dev->id); kfree(dev->id);
kfree(dev);
return NULL;
}
return dev; return ret;
} }
EXPORT_SYMBOL_GPL(ipack_device_register); EXPORT_SYMBOL_GPL(ipack_device_register);
......
...@@ -71,6 +71,7 @@ struct ipack_device { ...@@ -71,6 +71,7 @@ struct ipack_device {
struct ipack_addr_space int_space; struct ipack_addr_space int_space;
struct ipack_addr_space mem_space; struct ipack_addr_space mem_space;
struct device dev; struct device dev;
void (*release) (struct ipack_device *dev);
u8 *id; u8 *id;
size_t id_avail; size_t id_avail;
u32 id_vendor; u32 id_vendor;
...@@ -179,15 +180,17 @@ int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, ...@@ -179,15 +180,17 @@ int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
void ipack_driver_unregister(struct ipack_driver *edrv); void ipack_driver_unregister(struct ipack_driver *edrv);
/** /**
* ipack_device_register -- register a new mezzanine device * ipack_device_register -- register an IPack device with the kernel
* @dev: the new device to register.
* *
* @bus: ipack bus device it is plugged to. * Register a new IPack device ("module" in IndustryPack jargon). The call
* @slot: slot position in the bus device. * is done by the carrier driver. The carrier should populate the fields
* bus and slot of @dev prior to calling this function. The rest of the
* fields will be allocated and populated during registration.
* *
* Register a new ipack device (mezzanine device). The call is done by * Return zero on success or error code on failure.
* the carrier device driver.
*/ */
struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot); int ipack_device_register(struct ipack_device *dev);
void ipack_device_unregister(struct ipack_device *dev); void ipack_device_unregister(struct ipack_device *dev);
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment