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

net: devlink: add unlocked variants of devlink_region_create/destroy() functions

Add unlocked variants of devlink_region_create/destroy() functions
to be used in drivers called-in with devlink->lock held.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jiri Pirko and committed by
Jakub Kicinski
eb0e9fa2 72a4c8c9

+67 -29
+5
include/net/devlink.h
··· 1676 1676 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, 1677 1677 union devlink_param_value init_val); 1678 1678 void devlink_param_value_changed(struct devlink *devlink, u32 param_id); 1679 + struct devlink_region *devl_region_create(struct devlink *devlink, 1680 + const struct devlink_region_ops *ops, 1681 + u32 region_max_snapshots, 1682 + u64 region_size); 1679 1683 struct devlink_region * 1680 1684 devlink_region_create(struct devlink *devlink, 1681 1685 const struct devlink_region_ops *ops, ··· 1688 1684 devlink_port_region_create(struct devlink_port *port, 1689 1685 const struct devlink_port_region_ops *ops, 1690 1686 u32 region_max_snapshots, u64 region_size); 1687 + void devl_region_destroy(struct devlink_region *region); 1691 1688 void devlink_region_destroy(struct devlink_region *region); 1692 1689 void devlink_port_region_destroy(struct devlink_region *region); 1693 1690
+62 -29
net/core/devlink.c
··· 11192 11192 EXPORT_SYMBOL_GPL(devlink_param_value_changed); 11193 11193 11194 11194 /** 11195 - * devlink_region_create - create a new address region 11195 + * devl_region_create - create a new address region 11196 11196 * 11197 - * @devlink: devlink 11198 - * @ops: region operations and name 11199 - * @region_max_snapshots: Maximum supported number of snapshots for region 11200 - * @region_size: size of region 11197 + * @devlink: devlink 11198 + * @ops: region operations and name 11199 + * @region_max_snapshots: Maximum supported number of snapshots for region 11200 + * @region_size: size of region 11201 11201 */ 11202 - struct devlink_region * 11203 - devlink_region_create(struct devlink *devlink, 11204 - const struct devlink_region_ops *ops, 11205 - u32 region_max_snapshots, u64 region_size) 11202 + struct devlink_region *devl_region_create(struct devlink *devlink, 11203 + const struct devlink_region_ops *ops, 11204 + u32 region_max_snapshots, 11205 + u64 region_size) 11206 11206 { 11207 11207 struct devlink_region *region; 11208 - int err = 0; 11208 + 11209 + devl_assert_locked(devlink); 11209 11210 11210 11211 if (WARN_ON(!ops) || WARN_ON(!ops->destructor)) 11211 11212 return ERR_PTR(-EINVAL); 11212 11213 11213 - devl_lock(devlink); 11214 - 11215 - if (devlink_region_get_by_name(devlink, ops->name)) { 11216 - err = -EEXIST; 11217 - goto unlock; 11218 - } 11214 + if (devlink_region_get_by_name(devlink, ops->name)) 11215 + return ERR_PTR(-EEXIST); 11219 11216 11220 11217 region = kzalloc(sizeof(*region), GFP_KERNEL); 11221 - if (!region) { 11222 - err = -ENOMEM; 11223 - goto unlock; 11224 - } 11218 + if (!region) 11219 + return ERR_PTR(-ENOMEM); 11225 11220 11226 11221 region->devlink = devlink; 11227 11222 region->max_snapshots = region_max_snapshots; ··· 11226 11231 list_add_tail(&region->list, &devlink->region_list); 11227 11232 devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW); 11228 11233 11234 + return region; 11235 + } 11236 + EXPORT_SYMBOL_GPL(devl_region_create); 11237 + 11238 + /** 11239 + * devlink_region_create - create a new address region 11240 + * 11241 + * @devlink: devlink 11242 + * @ops: region operations and name 11243 + * @region_max_snapshots: Maximum supported number of snapshots for region 11244 + * @region_size: size of region 11245 + * 11246 + * Context: Takes and release devlink->lock <mutex>. 11247 + */ 11248 + struct devlink_region * 11249 + devlink_region_create(struct devlink *devlink, 11250 + const struct devlink_region_ops *ops, 11251 + u32 region_max_snapshots, u64 region_size) 11252 + { 11253 + struct devlink_region *region; 11254 + 11255 + devl_lock(devlink); 11256 + region = devl_region_create(devlink, ops, region_max_snapshots, 11257 + region_size); 11229 11258 devl_unlock(devlink); 11230 11259 return region; 11231 - 11232 - unlock: 11233 - devl_unlock(devlink); 11234 - return ERR_PTR(err); 11235 11260 } 11236 11261 EXPORT_SYMBOL_GPL(devlink_region_create); 11237 11262 ··· 11262 11247 * @ops: region operations and name 11263 11248 * @region_max_snapshots: Maximum supported number of snapshots for region 11264 11249 * @region_size: size of region 11250 + * 11251 + * Context: Takes and release devlink->lock <mutex>. 11265 11252 */ 11266 11253 struct devlink_region * 11267 11254 devlink_port_region_create(struct devlink_port *port, ··· 11309 11292 EXPORT_SYMBOL_GPL(devlink_port_region_create); 11310 11293 11311 11294 /** 11312 - * devlink_region_destroy - destroy address region 11295 + * devl_region_destroy - destroy address region 11313 11296 * 11314 - * @region: devlink region to destroy 11297 + * @region: devlink region to destroy 11315 11298 */ 11316 - void devlink_region_destroy(struct devlink_region *region) 11299 + void devl_region_destroy(struct devlink_region *region) 11317 11300 { 11318 11301 struct devlink *devlink = region->devlink; 11319 11302 struct devlink_snapshot *snapshot, *ts; 11320 11303 11321 - devl_lock(devlink); 11304 + devl_assert_locked(devlink); 11322 11305 11323 11306 /* Free all snapshots of region */ 11324 11307 list_for_each_entry_safe(snapshot, ts, &region->snapshot_list, list) ··· 11327 11310 list_del(&region->list); 11328 11311 11329 11312 devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_DEL); 11330 - devl_unlock(devlink); 11331 11313 kfree(region); 11314 + } 11315 + EXPORT_SYMBOL_GPL(devl_region_destroy); 11316 + 11317 + /** 11318 + * devlink_region_destroy - destroy address region 11319 + * 11320 + * @region: devlink region to destroy 11321 + * 11322 + * Context: Takes and release devlink->lock <mutex>. 11323 + */ 11324 + void devlink_region_destroy(struct devlink_region *region) 11325 + { 11326 + struct devlink *devlink = region->devlink; 11327 + 11328 + devl_lock(devlink); 11329 + devl_region_destroy(region); 11330 + devl_unlock(devlink); 11332 11331 } 11333 11332 EXPORT_SYMBOL_GPL(devlink_region_destroy); 11334 11333