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

libnvdimm: Move attribute groups to device type

Statically initialize the attribute groups for each libnvdimm
device_type. This is a preparation step for removing unnecessary exports
of attributes that can be included in the device_type by default.

Also take the opportunity to mark 'struct device_type' instances const.

Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Link: https://lore.kernel.org/r/157309900111.1582359.2445687530383470348.stgit@dwillia2-desk3.amr.corp.intel.com

+73 -76
+12 -12
drivers/nvdimm/btt_devs.c
··· 25 25 kfree(nd_btt); 26 26 } 27 27 28 - static struct device_type nd_btt_device_type = { 29 - .name = "nd_btt", 30 - .release = nd_btt_release, 31 - }; 32 - 33 - bool is_nd_btt(struct device *dev) 34 - { 35 - return dev->type == &nd_btt_device_type; 36 - } 37 - EXPORT_SYMBOL(is_nd_btt); 38 - 39 28 struct nd_btt *to_nd_btt(struct device *dev) 40 29 { 41 30 struct nd_btt *nd_btt = container_of(dev, struct nd_btt, dev); ··· 167 178 NULL, 168 179 }; 169 180 181 + static const struct device_type nd_btt_device_type = { 182 + .name = "nd_btt", 183 + .release = nd_btt_release, 184 + .groups = nd_btt_attribute_groups, 185 + }; 186 + 187 + bool is_nd_btt(struct device *dev) 188 + { 189 + return dev->type == &nd_btt_device_type; 190 + } 191 + EXPORT_SYMBOL(is_nd_btt); 192 + 170 193 static struct device *__nd_btt_create(struct nd_region *nd_region, 171 194 unsigned long lbasize, u8 *uuid, 172 195 struct nd_namespace_common *ndns) ··· 205 204 dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id); 206 205 dev->parent = &nd_region->dev; 207 206 dev->type = &nd_btt_device_type; 208 - dev->groups = nd_btt_attribute_groups; 209 207 device_initialize(&nd_btt->dev); 210 208 if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) { 211 209 dev_dbg(&ndns->dev, "failed, already claimed by %s\n",
+10 -17
drivers/nvdimm/dax_devs.c
··· 23 23 kfree(nd_dax); 24 24 } 25 25 26 - static struct device_type nd_dax_device_type = { 27 - .name = "nd_dax", 28 - .release = nd_dax_release, 29 - }; 30 - 31 - bool is_nd_dax(struct device *dev) 32 - { 33 - return dev ? dev->type == &nd_dax_device_type : false; 34 - } 35 - EXPORT_SYMBOL(is_nd_dax); 36 - 37 26 struct nd_dax *to_nd_dax(struct device *dev) 38 27 { 39 28 struct nd_dax *nd_dax = container_of(dev, struct nd_dax, nd_pfn.dev); ··· 32 43 } 33 44 EXPORT_SYMBOL(to_nd_dax); 34 45 35 - static const struct attribute_group *nd_dax_attribute_groups[] = { 36 - &nd_pfn_attribute_group, 37 - &nd_device_attribute_group, 38 - &nd_numa_attribute_group, 39 - NULL, 46 + static const struct device_type nd_dax_device_type = { 47 + .name = "nd_dax", 48 + .release = nd_dax_release, 49 + .groups = nd_pfn_attribute_groups, 40 50 }; 51 + 52 + bool is_nd_dax(struct device *dev) 53 + { 54 + return dev ? dev->type == &nd_dax_device_type : false; 55 + } 56 + EXPORT_SYMBOL(is_nd_dax); 41 57 42 58 static struct nd_dax *nd_dax_alloc(struct nd_region *nd_region) 43 59 { ··· 63 69 64 70 dev = &nd_pfn->dev; 65 71 dev_set_name(dev, "dax%d.%d", nd_region->id, nd_pfn->id); 66 - dev->groups = nd_dax_attribute_groups; 67 72 dev->type = &nd_dax_device_type; 68 73 dev->parent = &nd_region->dev; 69 74
+36 -32
drivers/nvdimm/namespace_devs.c
··· 44 44 kfree(nsblk); 45 45 } 46 46 47 - static const struct device_type namespace_io_device_type = { 48 - .name = "nd_namespace_io", 49 - .release = namespace_io_release, 50 - }; 51 - 52 - static const struct device_type namespace_pmem_device_type = { 53 - .name = "nd_namespace_pmem", 54 - .release = namespace_pmem_release, 55 - }; 56 - 57 - static const struct device_type namespace_blk_device_type = { 58 - .name = "nd_namespace_blk", 59 - .release = namespace_blk_release, 60 - }; 61 - 62 - static bool is_namespace_pmem(const struct device *dev) 63 - { 64 - return dev ? dev->type == &namespace_pmem_device_type : false; 65 - } 66 - 67 - static bool is_namespace_blk(const struct device *dev) 68 - { 69 - return dev ? dev->type == &namespace_blk_device_type : false; 70 - } 71 - 72 - static bool is_namespace_io(const struct device *dev) 73 - { 74 - return dev ? dev->type == &namespace_io_device_type : false; 75 - } 47 + static bool is_namespace_pmem(const struct device *dev); 48 + static bool is_namespace_blk(const struct device *dev); 49 + static bool is_namespace_io(const struct device *dev); 76 50 77 51 static int is_uuid_busy(struct device *dev, void *data) 78 52 { ··· 1654 1680 NULL, 1655 1681 }; 1656 1682 1683 + static const struct device_type namespace_io_device_type = { 1684 + .name = "nd_namespace_io", 1685 + .release = namespace_io_release, 1686 + .groups = nd_namespace_attribute_groups, 1687 + }; 1688 + 1689 + static const struct device_type namespace_pmem_device_type = { 1690 + .name = "nd_namespace_pmem", 1691 + .release = namespace_pmem_release, 1692 + .groups = nd_namespace_attribute_groups, 1693 + }; 1694 + 1695 + static const struct device_type namespace_blk_device_type = { 1696 + .name = "nd_namespace_blk", 1697 + .release = namespace_blk_release, 1698 + .groups = nd_namespace_attribute_groups, 1699 + }; 1700 + 1701 + static bool is_namespace_pmem(const struct device *dev) 1702 + { 1703 + return dev ? dev->type == &namespace_pmem_device_type : false; 1704 + } 1705 + 1706 + static bool is_namespace_blk(const struct device *dev) 1707 + { 1708 + return dev ? dev->type == &namespace_blk_device_type : false; 1709 + } 1710 + 1711 + static bool is_namespace_io(const struct device *dev) 1712 + { 1713 + return dev ? dev->type == &namespace_io_device_type : false; 1714 + } 1715 + 1657 1716 struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev) 1658 1717 { 1659 1718 struct nd_btt *nd_btt = is_nd_btt(dev) ? to_nd_btt(dev) : NULL; ··· 2102 2095 } 2103 2096 dev_set_name(dev, "namespace%d.%d", nd_region->id, nsblk->id); 2104 2097 dev->parent = &nd_region->dev; 2105 - dev->groups = nd_namespace_attribute_groups; 2106 2098 2107 2099 return &nsblk->common.dev; 2108 2100 } ··· 2132 2126 return NULL; 2133 2127 } 2134 2128 dev_set_name(dev, "namespace%d.%d", nd_region->id, nspm->id); 2135 - dev->groups = nd_namespace_attribute_groups; 2136 2129 nd_namespace_pmem_set_resource(nd_region, nspm, 0); 2137 2130 2138 2131 return dev; ··· 2630 2625 if (id < 0) 2631 2626 break; 2632 2627 dev_set_name(dev, "namespace%d.%d", nd_region->id, id); 2633 - dev->groups = nd_namespace_attribute_groups; 2634 2628 nd_device_register(dev); 2635 2629 } 2636 2630 if (i)
+1 -1
drivers/nvdimm/nd.h
··· 302 302 struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn, 303 303 struct nd_namespace_common *ndns); 304 304 int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig); 305 - extern struct attribute_group nd_pfn_attribute_group; 305 + extern const struct attribute_group *nd_pfn_attribute_groups[]; 306 306 #else 307 307 static inline int nd_pfn_probe(struct device *dev, 308 308 struct nd_namespace_common *ndns)
+14 -14
drivers/nvdimm/pfn_devs.c
··· 26 26 kfree(nd_pfn); 27 27 } 28 28 29 - static struct device_type nd_pfn_device_type = { 30 - .name = "nd_pfn", 31 - .release = nd_pfn_release, 32 - }; 33 - 34 - bool is_nd_pfn(struct device *dev) 35 - { 36 - return dev ? dev->type == &nd_pfn_device_type : false; 37 - } 38 - EXPORT_SYMBOL(is_nd_pfn); 39 - 40 29 struct nd_pfn *to_nd_pfn(struct device *dev) 41 30 { 42 31 struct nd_pfn *nd_pfn = container_of(dev, struct nd_pfn, dev); ··· 276 287 return a->mode; 277 288 } 278 289 279 - struct attribute_group nd_pfn_attribute_group = { 290 + static struct attribute_group nd_pfn_attribute_group = { 280 291 .attrs = nd_pfn_attributes, 281 292 .is_visible = pfn_visible, 282 293 }; 283 294 284 - static const struct attribute_group *nd_pfn_attribute_groups[] = { 295 + const struct attribute_group *nd_pfn_attribute_groups[] = { 285 296 &nd_pfn_attribute_group, 286 297 &nd_device_attribute_group, 287 298 &nd_numa_attribute_group, 288 299 NULL, 289 300 }; 301 + 302 + static const struct device_type nd_pfn_device_type = { 303 + .name = "nd_pfn", 304 + .release = nd_pfn_release, 305 + .groups = nd_pfn_attribute_groups, 306 + }; 307 + 308 + bool is_nd_pfn(struct device *dev) 309 + { 310 + return dev ? dev->type == &nd_pfn_device_type : false; 311 + } 312 + EXPORT_SYMBOL(is_nd_pfn); 290 313 291 314 struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn, 292 315 struct nd_namespace_common *ndns) ··· 338 337 339 338 dev = &nd_pfn->dev; 340 339 dev_set_name(dev, "pfn%d.%d", nd_region->id, nd_pfn->id); 341 - dev->groups = nd_pfn_attribute_groups; 342 340 dev->type = &nd_pfn_device_type; 343 341 dev->parent = &nd_region->dev; 344 342