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

cfg802154: introduce cfg802154_registered_device

This patch introduce the cfg802154_registered_device struct. Like
cfg80211_registered_device in wireless this should contain similar
functionality for cfg802154. This patch should not change any behaviour.
We just adds cfg802154_registered_device as container for wpan_phy struct.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Alexander Aring and committed by
Marcel Holtmann
a5dd1d72 fe58d016

+64 -18
+7 -1
include/net/cfg802154.h
··· 29 29 #define WPAN_NUM_CHANNELS 27 30 30 #define WPAN_NUM_PAGES 32 31 31 32 + struct wpan_phy; 33 + 34 + struct cfg802154_ops { 35 + }; 36 + 32 37 struct wpan_phy { 33 38 struct mutex pib_lock; 34 39 ··· 67 62 68 63 #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev) 69 64 70 - struct wpan_phy *wpan_phy_alloc(size_t priv_size); 65 + struct wpan_phy * 66 + wpan_phy_alloc(const struct cfg802154_ops *ops, size_t priv_size); 71 67 static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev) 72 68 { 73 69 phy->dev.parent = dev;
+26 -13
net/ieee802154/core.c
··· 21 21 22 22 #include "ieee802154.h" 23 23 #include "sysfs.h" 24 + #include "core.h" 24 25 25 26 static DEFINE_MUTEX(wpan_phy_mutex); 26 27 static int wpan_phy_idx; ··· 77 76 return idx >= 0; 78 77 } 79 78 80 - struct wpan_phy *wpan_phy_alloc(size_t priv_size) 79 + struct wpan_phy * 80 + wpan_phy_alloc(const struct cfg802154_ops *ops, size_t priv_size) 81 81 { 82 - struct wpan_phy *phy = kzalloc(sizeof(*phy) + priv_size, 83 - GFP_KERNEL); 82 + struct cfg802154_registered_device *rdev; 83 + size_t alloc_size; 84 84 85 - if (!phy) 86 - goto out; 85 + alloc_size = sizeof(*rdev) + priv_size; 86 + rdev = kzalloc(alloc_size, GFP_KERNEL); 87 + if (!rdev) 88 + return NULL; 89 + 90 + rdev->ops = ops; 91 + 87 92 mutex_lock(&wpan_phy_mutex); 88 - phy->idx = wpan_phy_idx++; 89 - if (unlikely(!wpan_phy_idx_valid(phy->idx))) { 93 + rdev->wpan_phy.idx = wpan_phy_idx++; 94 + if (unlikely(!wpan_phy_idx_valid(rdev->wpan_phy.idx))) { 90 95 wpan_phy_idx--; 91 96 mutex_unlock(&wpan_phy_mutex); 92 - kfree(phy); 97 + kfree(rdev); 93 98 goto out; 94 99 } 95 100 mutex_unlock(&wpan_phy_mutex); 96 101 97 - mutex_init(&phy->pib_lock); 102 + mutex_init(&rdev->wpan_phy.pib_lock); 98 103 99 - device_initialize(&phy->dev); 100 - dev_set_name(&phy->dev, "wpan-phy%d", phy->idx); 104 + device_initialize(&rdev->wpan_phy.dev); 105 + dev_set_name(&rdev->wpan_phy.dev, "wpan-phy%d", rdev->wpan_phy.idx); 101 106 102 - phy->dev.class = &wpan_phy_class; 107 + rdev->wpan_phy.dev.class = &wpan_phy_class; 108 + rdev->wpan_phy.dev.platform_data = rdev; 103 109 104 - return phy; 110 + return &rdev->wpan_phy; 105 111 106 112 out: 107 113 return NULL; ··· 132 124 put_device(&phy->dev); 133 125 } 134 126 EXPORT_SYMBOL(wpan_phy_free); 127 + 128 + void cfg802154_dev_free(struct cfg802154_registered_device *rdev) 129 + { 130 + kfree(rdev); 131 + } 135 132 136 133 static int __init wpan_phy_class_init(void) 137 134 {
+18
net/ieee802154/core.h
··· 1 + #ifndef __IEEE802154_CORE_H 2 + #define __IEEE802154_CORE_H 3 + 4 + #include <net/cfg802154.h> 5 + 6 + struct cfg802154_registered_device { 7 + const struct cfg802154_ops *ops; 8 + 9 + /* must be last because of the way we do wpan_phy_priv(), 10 + * and it should at least be aligned to NETDEV_ALIGN 11 + */ 12 + struct wpan_phy wpan_phy __aligned(NETDEV_ALIGN); 13 + }; 14 + 15 + /* free object */ 16 + void cfg802154_dev_free(struct cfg802154_registered_device *rdev); 17 + 18 + #endif /* __IEEE802154_CORE_H */
+12 -3
net/ieee802154/sysfs.c
··· 17 17 18 18 #include <net/cfg802154.h> 19 19 20 + #include "core.h" 21 + 22 + static inline struct cfg802154_registered_device * 23 + dev_to_rdev(struct device *dev) 24 + { 25 + return container_of(dev, struct cfg802154_registered_device, 26 + wpan_phy.dev); 27 + } 28 + 20 29 #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ 21 30 static ssize_t name ## _show(struct device *dev, \ 22 31 struct device_attribute *attr, char *buf) \ ··· 69 60 } 70 61 static DEVICE_ATTR_RO(channels_supported); 71 62 72 - static void wpan_phy_release(struct device *d) 63 + static void wpan_phy_release(struct device *dev) 73 64 { 74 - struct wpan_phy *phy = container_of(d, struct wpan_phy, dev); 65 + struct cfg802154_registered_device *rdev = dev_to_rdev(dev); 75 66 76 - kfree(phy); 67 + cfg802154_dev_free(rdev); 77 68 } 78 69 79 70 static struct attribute *pmib_attrs[] = {
+1 -1
net/mac802154/main.c
··· 169 169 170 170 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len; 171 171 172 - phy = wpan_phy_alloc(priv_size); 172 + phy = wpan_phy_alloc(NULL, priv_size); 173 173 if (!phy) { 174 174 pr_err("failure to allocate master IEEE802.15.4 device\n"); 175 175 return NULL;