thp: skip transhuge pages in ksm for now
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / uwb / umc-dev.c
blobccd2184e05d245a9521757a170883ed3b5197013
1 /*
2 * UWB Multi-interface Controller device management.
4 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
6 * This file is released under the GNU GPL v2.
7 */
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
10 #include <linux/uwb/umc.h>
12 static void umc_device_release(struct device *dev)
14 struct umc_dev *umc = to_umc_dev(dev);
16 kfree(umc);
19 /**
20 * umc_device_create - allocate a child UMC device
21 * @parent: parent of the new UMC device.
22 * @n: index of the new device.
24 * The new UMC device will have a bus ID of the parent with '-n'
25 * appended.
27 struct umc_dev *umc_device_create(struct device *parent, int n)
29 struct umc_dev *umc;
31 umc = kzalloc(sizeof(struct umc_dev), GFP_KERNEL);
32 if (umc) {
33 dev_set_name(&umc->dev, "%s-%d", dev_name(parent), n);
34 umc->dev.parent = parent;
35 umc->dev.bus = &umc_bus_type;
36 umc->dev.release = umc_device_release;
38 umc->dev.dma_mask = parent->dma_mask;
40 return umc;
42 EXPORT_SYMBOL_GPL(umc_device_create);
44 /**
45 * umc_device_register - register a UMC device
46 * @umc: pointer to the UMC device
48 * The memory resource for the UMC device is acquired and the device
49 * registered with the system.
51 int umc_device_register(struct umc_dev *umc)
53 int err;
55 err = request_resource(umc->resource.parent, &umc->resource);
56 if (err < 0) {
57 dev_err(&umc->dev, "can't allocate resource range %pR: %d\n",
58 &umc->resource, err);
59 goto error_request_resource;
62 err = device_register(&umc->dev);
63 if (err < 0)
64 goto error_device_register;
65 return 0;
67 error_device_register:
68 release_resource(&umc->resource);
69 error_request_resource:
70 return err;
72 EXPORT_SYMBOL_GPL(umc_device_register);
74 /**
75 * umc_device_unregister - unregister a UMC device
76 * @umc: pointer to the UMC device
78 * First we unregister the device, make sure the driver can do it's
79 * resource release thing and then we try to release any left over
80 * resources. We take a ref to the device, to make sure it doesn't
81 * dissapear under our feet.
83 void umc_device_unregister(struct umc_dev *umc)
85 struct device *dev;
86 if (!umc)
87 return;
88 dev = get_device(&umc->dev);
89 device_unregister(&umc->dev);
90 release_resource(&umc->resource);
91 put_device(dev);
93 EXPORT_SYMBOL_GPL(umc_device_unregister);