Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[Bluetooth] Use real devices for host controllers

This patch converts the Bluetooth class devices into real devices. The
Bluetooth class is kept and the driver core provides the appropriate
symlinks for backward compatibility.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Marcel Holtmann and committed by
David S. Miller
a91f2e39 27d35284

+79 -101
+1 -1
include/net/bluetooth/bluetooth.h
··· 175 175 extern int bt_sysfs_init(void); 176 176 extern void bt_sysfs_cleanup(void); 177 177 178 - extern struct class bt_class; 178 + extern struct class *bt_class; 179 179 180 180 #endif /* __BLUETOOTH_H */
+3 -3
include/net/bluetooth/hci_core.h
··· 124 124 125 125 atomic_t promisc; 126 126 127 - struct device *dev; 128 - struct class_device class_dev; 127 + struct device *parent; 128 + struct device dev; 129 129 130 130 struct module *owner; 131 131 ··· 413 413 int hci_register_sysfs(struct hci_dev *hdev); 414 414 void hci_unregister_sysfs(struct hci_dev *hdev); 415 415 416 - #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->class_dev.dev = (pdev)) 416 + #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev)) 417 417 418 418 /* ----- LMP capabilities ----- */ 419 419 #define lmp_rswitch_capable(dev) ((dev)->features[0] & LMP_RSWITCH)
+2 -2
net/bluetooth/hci_core.c
··· 817 817 { 818 818 skb_queue_purge(&hdev->driver_init); 819 819 820 - /* will free via class release */ 821 - class_device_put(&hdev->class_dev); 820 + /* will free via device release */ 821 + put_device(&hdev->dev); 822 822 } 823 823 EXPORT_SYMBOL(hci_free_dev); 824 824
+65 -87
net/bluetooth/hci_sysfs.c
··· 13 13 #define BT_DBG(D...) 14 14 #endif 15 15 16 - static ssize_t show_name(struct class_device *cdev, char *buf) 16 + static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) 17 17 { 18 - struct hci_dev *hdev = class_get_devdata(cdev); 18 + struct hci_dev *hdev = dev_get_drvdata(dev); 19 19 return sprintf(buf, "%s\n", hdev->name); 20 20 } 21 21 22 - static ssize_t show_type(struct class_device *cdev, char *buf) 22 + static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) 23 23 { 24 - struct hci_dev *hdev = class_get_devdata(cdev); 24 + struct hci_dev *hdev = dev_get_drvdata(dev); 25 25 return sprintf(buf, "%d\n", hdev->type); 26 26 } 27 27 28 - static ssize_t show_address(struct class_device *cdev, char *buf) 28 + static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) 29 29 { 30 - struct hci_dev *hdev = class_get_devdata(cdev); 30 + struct hci_dev *hdev = dev_get_drvdata(dev); 31 31 bdaddr_t bdaddr; 32 32 baswap(&bdaddr, &hdev->bdaddr); 33 33 return sprintf(buf, "%s\n", batostr(&bdaddr)); 34 34 } 35 35 36 - static ssize_t show_flags(struct class_device *cdev, char *buf) 36 + static ssize_t show_flags(struct device *dev, struct device_attribute *attr, char *buf) 37 37 { 38 - struct hci_dev *hdev = class_get_devdata(cdev); 38 + struct hci_dev *hdev = dev_get_drvdata(dev); 39 39 return sprintf(buf, "0x%lx\n", hdev->flags); 40 40 } 41 41 42 - static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf) 42 + static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf) 43 43 { 44 - struct hci_dev *hdev = class_get_devdata(cdev); 44 + struct hci_dev *hdev = dev_get_drvdata(dev); 45 45 struct inquiry_cache *cache = &hdev->inq_cache; 46 46 struct inquiry_entry *e; 47 47 int n = 0; ··· 63 63 return n; 64 64 } 65 65 66 - static ssize_t show_idle_timeout(struct class_device *cdev, char *buf) 66 + static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) 67 67 { 68 - struct hci_dev *hdev = class_get_devdata(cdev); 68 + struct hci_dev *hdev = dev_get_drvdata(dev); 69 69 return sprintf(buf, "%d\n", hdev->idle_timeout); 70 70 } 71 71 72 - static ssize_t store_idle_timeout(struct class_device *cdev, const char *buf, size_t count) 72 + static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 73 73 { 74 - struct hci_dev *hdev = class_get_devdata(cdev); 74 + struct hci_dev *hdev = dev_get_drvdata(dev); 75 75 char *ptr; 76 76 __u32 val; 77 77 ··· 87 87 return count; 88 88 } 89 89 90 - static ssize_t show_sniff_max_interval(struct class_device *cdev, char *buf) 90 + static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf) 91 91 { 92 - struct hci_dev *hdev = class_get_devdata(cdev); 92 + struct hci_dev *hdev = dev_get_drvdata(dev); 93 93 return sprintf(buf, "%d\n", hdev->sniff_max_interval); 94 94 } 95 95 96 - static ssize_t store_sniff_max_interval(struct class_device *cdev, const char *buf, size_t count) 96 + static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 97 97 { 98 - struct hci_dev *hdev = class_get_devdata(cdev); 98 + struct hci_dev *hdev = dev_get_drvdata(dev); 99 99 char *ptr; 100 100 __u16 val; 101 101 ··· 114 114 return count; 115 115 } 116 116 117 - static ssize_t show_sniff_min_interval(struct class_device *cdev, char *buf) 117 + static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf) 118 118 { 119 - struct hci_dev *hdev = class_get_devdata(cdev); 119 + struct hci_dev *hdev = dev_get_drvdata(dev); 120 120 return sprintf(buf, "%d\n", hdev->sniff_min_interval); 121 121 } 122 122 123 - static ssize_t store_sniff_min_interval(struct class_device *cdev, const char *buf, size_t count) 123 + static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 124 124 { 125 - struct hci_dev *hdev = class_get_devdata(cdev); 125 + struct hci_dev *hdev = dev_get_drvdata(dev); 126 126 char *ptr; 127 127 __u16 val; 128 128 ··· 141 141 return count; 142 142 } 143 143 144 - static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 145 - static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL); 146 - static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL); 147 - static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); 148 - static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); 144 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 145 + static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); 146 + static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); 147 + static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); 148 + static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); 149 149 150 - static CLASS_DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, 150 + static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, 151 151 show_idle_timeout, store_idle_timeout); 152 - static CLASS_DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, 152 + static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, 153 153 show_sniff_max_interval, store_sniff_max_interval); 154 - static CLASS_DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, 154 + static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, 155 155 show_sniff_min_interval, store_sniff_min_interval); 156 156 157 - static struct class_device_attribute *bt_attrs[] = { 158 - &class_device_attr_name, 159 - &class_device_attr_type, 160 - &class_device_attr_address, 161 - &class_device_attr_flags, 162 - &class_device_attr_inquiry_cache, 163 - &class_device_attr_idle_timeout, 164 - &class_device_attr_sniff_max_interval, 165 - &class_device_attr_sniff_min_interval, 157 + static struct device_attribute *bt_attrs[] = { 158 + &dev_attr_name, 159 + &dev_attr_type, 160 + &dev_attr_address, 161 + &dev_attr_flags, 162 + &dev_attr_inquiry_cache, 163 + &dev_attr_idle_timeout, 164 + &dev_attr_sniff_max_interval, 165 + &dev_attr_sniff_min_interval, 166 166 NULL 167 167 }; 168 168 169 - #ifdef CONFIG_HOTPLUG 170 - static int bt_uevent(struct class_device *cdev, char **envp, int num_envp, char *buf, int size) 171 - { 172 - struct hci_dev *hdev = class_get_devdata(cdev); 173 - int n, i = 0; 174 - 175 - envp[i++] = buf; 176 - n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1; 177 - buf += n; 178 - size -= n; 179 - 180 - if ((size <= 0) || (i >= num_envp)) 181 - return -ENOMEM; 182 - 183 - envp[i] = NULL; 184 - return 0; 185 - } 186 - #endif 187 - 188 - static void bt_release(struct class_device *cdev) 189 - { 190 - struct hci_dev *hdev = class_get_devdata(cdev); 191 - 192 - kfree(hdev); 193 - } 194 - 195 - struct class bt_class = { 196 - .name = "bluetooth", 197 - .release = bt_release, 198 - #ifdef CONFIG_HOTPLUG 199 - .uevent = bt_uevent, 200 - #endif 201 - }; 169 + struct class *bt_class = NULL; 202 170 EXPORT_SYMBOL_GPL(bt_class); 203 171 204 172 static struct bus_type bt_bus = { ··· 175 207 176 208 static struct platform_device *bt_platform; 177 209 210 + static void bt_release(struct device *dev) 211 + { 212 + struct hci_dev *hdev = dev_get_drvdata(dev); 213 + kfree(hdev); 214 + } 215 + 178 216 int hci_register_sysfs(struct hci_dev *hdev) 179 217 { 180 - struct class_device *cdev = &hdev->class_dev; 218 + struct device *dev = &hdev->dev; 181 219 unsigned int i; 182 220 int err; 183 221 184 222 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); 185 223 186 - cdev->class = &bt_class; 187 - class_set_devdata(cdev, hdev); 224 + dev->class = bt_class; 188 225 189 - if (!cdev->dev) 190 - cdev->dev = &bt_platform->dev; 226 + if (hdev->parent) 227 + dev->parent = hdev->parent; 228 + else 229 + dev->parent = &bt_platform->dev; 191 230 192 - hdev->dev = cdev->dev; 231 + strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); 193 232 194 - strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE); 195 - err = class_device_register(cdev); 233 + dev->release = bt_release; 234 + 235 + dev_set_drvdata(dev, hdev); 236 + 237 + err = device_register(dev); 196 238 if (err < 0) 197 239 return err; 198 240 199 241 for (i = 0; bt_attrs[i]; i++) 200 - class_device_create_file(cdev, bt_attrs[i]); 242 + device_create_file(dev, bt_attrs[i]); 201 243 202 244 return 0; 203 245 } 204 246 205 247 void hci_unregister_sysfs(struct hci_dev *hdev) 206 248 { 207 - struct class_device * cdev = &hdev->class_dev; 249 + struct device *dev = &hdev->dev; 208 250 209 251 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); 210 252 211 - class_device_del(cdev); 253 + device_del(dev); 212 254 } 213 255 214 256 int __init bt_sysfs_init(void) ··· 235 257 return err; 236 258 } 237 259 238 - err = class_register(&bt_class); 239 - if (err < 0) { 260 + bt_class = class_create(THIS_MODULE, "bluetooth"); 261 + if (IS_ERR(bt_class)) { 240 262 bus_unregister(&bt_bus); 241 263 platform_device_unregister(bt_platform); 242 - return err; 264 + return PTR_ERR(bt_class); 243 265 } 244 266 245 267 return 0; ··· 247 269 248 270 void __exit bt_sysfs_cleanup(void) 249 271 { 250 - class_unregister(&bt_class); 272 + class_destroy(bt_class); 251 273 252 274 bus_unregister(&bt_bus); 253 275
+2 -2
net/bluetooth/l2cap.c
··· 2219 2219 goto error; 2220 2220 } 2221 2221 2222 - class_create_file(&bt_class, &class_attr_l2cap); 2222 + class_create_file(bt_class, &class_attr_l2cap); 2223 2223 2224 2224 BT_INFO("L2CAP ver %s", VERSION); 2225 2225 BT_INFO("L2CAP socket layer initialized"); ··· 2233 2233 2234 2234 static void __exit l2cap_exit(void) 2235 2235 { 2236 - class_remove_file(&bt_class, &class_attr_l2cap); 2236 + class_remove_file(bt_class, &class_attr_l2cap); 2237 2237 2238 2238 if (bt_sock_unregister(BTPROTO_L2CAP) < 0) 2239 2239 BT_ERR("L2CAP socket unregistration failed");
+2 -2
net/bluetooth/rfcomm/core.c
··· 2035 2035 2036 2036 kernel_thread(rfcomm_run, NULL, CLONE_KERNEL); 2037 2037 2038 - class_create_file(&bt_class, &class_attr_rfcomm_dlc); 2038 + class_create_file(bt_class, &class_attr_rfcomm_dlc); 2039 2039 2040 2040 rfcomm_init_sockets(); 2041 2041 ··· 2050 2050 2051 2051 static void __exit rfcomm_exit(void) 2052 2052 { 2053 - class_remove_file(&bt_class, &class_attr_rfcomm_dlc); 2053 + class_remove_file(bt_class, &class_attr_rfcomm_dlc); 2054 2054 2055 2055 hci_unregister_cb(&rfcomm_cb); 2056 2056
+2 -2
net/bluetooth/rfcomm/sock.c
··· 944 944 if (err < 0) 945 945 goto error; 946 946 947 - class_create_file(&bt_class, &class_attr_rfcomm); 947 + class_create_file(bt_class, &class_attr_rfcomm); 948 948 949 949 BT_INFO("RFCOMM socket layer initialized"); 950 950 ··· 958 958 959 959 void __exit rfcomm_cleanup_sockets(void) 960 960 { 961 - class_remove_file(&bt_class, &class_attr_rfcomm); 961 + class_remove_file(bt_class, &class_attr_rfcomm); 962 962 963 963 if (bt_sock_unregister(BTPROTO_RFCOMM) < 0) 964 964 BT_ERR("RFCOMM socket layer unregistration failed");
+2 -2
net/bluetooth/sco.c
··· 969 969 goto error; 970 970 } 971 971 972 - class_create_file(&bt_class, &class_attr_sco); 972 + class_create_file(bt_class, &class_attr_sco); 973 973 974 974 BT_INFO("SCO (Voice Link) ver %s", VERSION); 975 975 BT_INFO("SCO socket layer initialized"); ··· 983 983 984 984 static void __exit sco_exit(void) 985 985 { 986 - class_remove_file(&bt_class, &class_attr_sco); 986 + class_remove_file(bt_class, &class_attr_sco); 987 987 988 988 if (bt_sock_unregister(BTPROTO_SCO) < 0) 989 989 BT_ERR("SCO socket unregistration failed");