Commit 91c0e9d6 authored by Li Ming's avatar Li Ming Committed by Dave Jiang
Browse files

cxl/port: Refactor __devm_cxl_add_port() to drop goto pattern



In __devm_cxl_add_port(), there is a 'goto' to call put_device() for the
error cases between device_initialize() and device_add() to dereference
the 'struct device' of a new cxl_port. The 'goto' pattern in the case
can be removed by refactoring. Introducing a new function called
cxl_port_add() which is used to add the 'struct device' of a new
cxl_port to device hierarchy, moving the functions needing the help of
the 'goto' into cxl_port_add(), and using a scoped-based resource
management __free() to drop the open coded put_device() and the 'goto'
for the error cases.

Suggested-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarLi Ming <ming4.li@intel.com>
Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huwaei.com>
Link: https://patch.msgid.link/20240830013138.2256244-3-ming4.li@intel.com


Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
parent 7f569e91
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment