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

fpga: bridge: add devm_fpga_bridge_create

Add devm_fpga_bridge_create() which is the managed
version of fpga_bridge_create().

Change current bridge drivers to use
devm_fpga_bridge_create().

Signed-off-by: Alan Tull <atull@kernel.org>
Suggested-by: Federico Vaga <federico.vaga@cern.ch>
Acked-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Tull and committed by
Greg Kroah-Hartman
213befe0 084181fe

+80 -38
+3
Documentation/driver-api/fpga/fpga-bridge.rst
··· 11 11 :functions: fpga_bridge_ops 12 12 13 13 .. kernel-doc:: drivers/fpga/fpga-bridge.c 14 + :functions: devm_fpga_bridge_create 15 + 16 + .. kernel-doc:: drivers/fpga/fpga-bridge.c 14 17 :functions: fpga_bridge_create 15 18 16 19 .. kernel-doc:: drivers/fpga/fpga-bridge.c
+3 -5
drivers/fpga/altera-fpga2sdram.c
··· 121 121 /* Get f2s bridge configuration saved in handoff register */ 122 122 regmap_read(sysmgr, SYSMGR_ISWGRP_HANDOFF3, &priv->mask); 123 123 124 - br = fpga_bridge_create(dev, F2S_BRIDGE_NAME, 125 - &altera_fpga2sdram_br_ops, priv); 124 + br = devm_fpga_bridge_create(dev, F2S_BRIDGE_NAME, 125 + &altera_fpga2sdram_br_ops, priv); 126 126 if (!br) 127 127 return -ENOMEM; 128 128 129 129 platform_set_drvdata(pdev, br); 130 130 131 131 ret = fpga_bridge_register(br); 132 - if (ret) { 133 - fpga_bridge_free(br); 132 + if (ret) 134 133 return ret; 135 - } 136 134 137 135 dev_info(dev, "driver initialized with handoff %08x\n", priv->mask); 138 136
+3 -10
drivers/fpga/altera-freeze-bridge.c
··· 213 213 struct fpga_bridge *br; 214 214 struct resource *res; 215 215 u32 status, revision; 216 - int ret; 217 216 218 217 if (!np) 219 218 return -ENODEV; ··· 244 245 245 246 priv->base_addr = base_addr; 246 247 247 - br = fpga_bridge_create(dev, FREEZE_BRIDGE_NAME, 248 - &altera_freeze_br_br_ops, priv); 248 + br = devm_fpga_bridge_create(dev, FREEZE_BRIDGE_NAME, 249 + &altera_freeze_br_br_ops, priv); 249 250 if (!br) 250 251 return -ENOMEM; 251 252 252 253 platform_set_drvdata(pdev, br); 253 254 254 - ret = fpga_bridge_register(br); 255 - if (ret) { 256 - fpga_bridge_free(br); 257 - return ret; 258 - } 259 - 260 - return 0; 255 + return fpga_bridge_register(br); 261 256 } 262 257 263 258 static int altera_freeze_br_remove(struct platform_device *pdev)
+3 -4
drivers/fpga/altera-hps2fpga.c
··· 180 180 } 181 181 } 182 182 183 - br = fpga_bridge_create(dev, priv->name, &altera_hps2fpga_br_ops, priv); 183 + br = devm_fpga_bridge_create(dev, priv->name, 184 + &altera_hps2fpga_br_ops, priv); 184 185 if (!br) { 185 186 ret = -ENOMEM; 186 187 goto err; ··· 191 190 192 191 ret = fpga_bridge_register(br); 193 192 if (ret) 194 - goto err_free; 193 + goto err; 195 194 196 195 return 0; 197 196 198 - err_free: 199 - fpga_bridge_free(br); 200 197 err: 201 198 clk_disable_unprepare(priv->clk); 202 199
+3 -8
drivers/fpga/dfl-fme-br.c
··· 61 61 struct device *dev = &pdev->dev; 62 62 struct fme_br_priv *priv; 63 63 struct fpga_bridge *br; 64 - int ret; 65 64 66 65 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 67 66 if (!priv) ··· 68 69 69 70 priv->pdata = dev_get_platdata(dev); 70 71 71 - br = fpga_bridge_create(dev, "DFL FPGA FME Bridge", 72 - &fme_bridge_ops, priv); 72 + br = devm_fpga_bridge_create(dev, "DFL FPGA FME Bridge", 73 + &fme_bridge_ops, priv); 73 74 if (!br) 74 75 return -ENOMEM; 75 76 76 77 platform_set_drvdata(pdev, br); 77 78 78 - ret = fpga_bridge_register(br); 79 - if (ret) 80 - fpga_bridge_free(br); 81 - 82 - return ret; 79 + return fpga_bridge_register(br); 83 80 } 84 81 85 82 static int fme_br_remove(struct platform_device *pdev)
+59 -9
drivers/fpga/fpga-bridge.c
··· 324 324 * @br_ops: pointer to structure of fpga bridge ops 325 325 * @priv: FPGA bridge private data 326 326 * 327 + * The caller of this function is responsible for freeing the bridge with 328 + * fpga_bridge_free(). Using devm_fpga_bridge_create() instead is recommended. 329 + * 327 330 * Return: struct fpga_bridge or NULL 328 331 */ 329 332 struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name, ··· 381 378 EXPORT_SYMBOL_GPL(fpga_bridge_create); 382 379 383 380 /** 384 - * fpga_bridge_free - free a fpga bridge and its id 385 - * @bridge: FPGA bridge struct created by fpga_bridge_create 381 + * fpga_bridge_free - free a fpga bridge created by fpga_bridge_create() 382 + * @bridge: FPGA bridge struct 386 383 */ 387 384 void fpga_bridge_free(struct fpga_bridge *bridge) 388 385 { ··· 391 388 } 392 389 EXPORT_SYMBOL_GPL(fpga_bridge_free); 393 390 391 + static void devm_fpga_bridge_release(struct device *dev, void *res) 392 + { 393 + struct fpga_bridge *bridge = *(struct fpga_bridge **)res; 394 + 395 + fpga_bridge_free(bridge); 396 + } 397 + 394 398 /** 395 - * fpga_bridge_register - register a fpga bridge 396 - * @bridge: FPGA bridge struct created by fpga_bridge_create 399 + * devm_fpga_bridge_create - create and init a managed struct fpga_bridge 400 + * @dev: FPGA bridge device from pdev 401 + * @name: FPGA bridge name 402 + * @br_ops: pointer to structure of fpga bridge ops 403 + * @priv: FPGA bridge private data 404 + * 405 + * This function is intended for use in a FPGA bridge driver's probe function. 406 + * After the bridge driver creates the struct with devm_fpga_bridge_create(), it 407 + * should register the bridge with fpga_bridge_register(). The bridge driver's 408 + * remove function should call fpga_bridge_unregister(). The bridge struct 409 + * allocated with this function will be freed automatically on driver detach. 410 + * This includes the case of a probe function returning error before calling 411 + * fpga_bridge_register(), the struct will still get cleaned up. 412 + * 413 + * Return: struct fpga_bridge or NULL 414 + */ 415 + struct fpga_bridge 416 + *devm_fpga_bridge_create(struct device *dev, const char *name, 417 + const struct fpga_bridge_ops *br_ops, void *priv) 418 + { 419 + struct fpga_bridge **ptr, *bridge; 420 + 421 + ptr = devres_alloc(devm_fpga_bridge_release, sizeof(*ptr), GFP_KERNEL); 422 + if (!ptr) 423 + return NULL; 424 + 425 + bridge = fpga_bridge_create(dev, name, br_ops, priv); 426 + if (!bridge) { 427 + devres_free(ptr); 428 + } else { 429 + *ptr = bridge; 430 + devres_add(dev, ptr); 431 + } 432 + 433 + return bridge; 434 + } 435 + EXPORT_SYMBOL_GPL(devm_fpga_bridge_create); 436 + 437 + /** 438 + * fpga_bridge_register - register a FPGA bridge 439 + * 440 + * @bridge: FPGA bridge struct 397 441 * 398 442 * Return: 0 for success, error code otherwise. 399 443 */ ··· 462 412 EXPORT_SYMBOL_GPL(fpga_bridge_register); 463 413 464 414 /** 465 - * fpga_bridge_unregister - unregister and free a fpga bridge 466 - * @bridge: FPGA bridge struct created by fpga_bridge_create 415 + * fpga_bridge_unregister - unregister a FPGA bridge 416 + * 417 + * @bridge: FPGA bridge struct 418 + * 419 + * This function is intended for use in a FPGA bridge driver's remove function. 467 420 */ 468 421 void fpga_bridge_unregister(struct fpga_bridge *bridge) 469 422 { ··· 483 430 484 431 static void fpga_bridge_dev_release(struct device *dev) 485 432 { 486 - struct fpga_bridge *bridge = to_fpga_bridge(dev); 487 - 488 - fpga_bridge_free(bridge); 489 433 } 490 434 491 435 static int __init fpga_bridge_dev_init(void)
+2 -2
drivers/fpga/xilinx-pr-decoupler.c
··· 121 121 122 122 clk_disable(priv->clk); 123 123 124 - br = fpga_bridge_create(&pdev->dev, "Xilinx PR Decoupler", 125 - &xlnx_pr_decoupler_br_ops, priv); 124 + br = devm_fpga_bridge_create(&pdev->dev, "Xilinx PR Decoupler", 125 + &xlnx_pr_decoupler_br_ops, priv); 126 126 if (!br) { 127 127 err = -ENOMEM; 128 128 goto err_clk;
+4
include/linux/fpga/fpga-bridge.h
··· 69 69 int fpga_bridge_register(struct fpga_bridge *br); 70 70 void fpga_bridge_unregister(struct fpga_bridge *br); 71 71 72 + struct fpga_bridge 73 + *devm_fpga_bridge_create(struct device *dev, const char *name, 74 + const struct fpga_bridge_ops *br_ops, void *priv); 75 + 72 76 #endif /* _LINUX_FPGA_BRIDGE_H */