]> git.ipfire.org Git - thirdparty/linux.git/commit
cxl/port: Refactor __devm_cxl_add_port() to drop goto pattern
authorLi Ming <ming4.li@intel.com>
Fri, 30 Aug 2024 01:31:38 +0000 (01:31 +0000)
committerDave Jiang <dave.jiang@intel.com>
Tue, 3 Sep 2024 21:49:49 +0000 (14:49 -0700)
commit91c0e9d6a205ab0e318dc0dc6e72cbbdb21f8094
tree1775cab865b92e0a5dbb0c131bb6cf0a5e15c90e
parent7f569e917b7866b6760e2cfc3a9549cabc890071
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: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Li Ming <ming4.li@intel.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huwaei.com>
Link: https://patch.msgid.link/20240830013138.2256244-3-ming4.li@intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/port.c