Re: [PATCH v2 3/3] cxl/port: Refactor __devm_cxl_add_port() to drop goto pattern

Li, Ming4
2024-08-28T01:34:02Z

On 8/27/2024 8:05 PM, Jonathan Cameron wrote:
> On Mon, 26 Aug 2024 08:30:58 +0000
> Li Ming <ming4.li@intel.com> wrote:
>
>> The "goto error" pattern is not recommended, it can be removed via
>> refactoring.
> I'd avoid this first comment. Goto error is fine, but not when
> it is not used for all error paths after the first one where it's
> relevant (which is what is happening here)

Sure, will remove it, thanks.

>
>> 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 refactoring is 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 above
>> 'goto' into cxl_port_add(), and using a scope-based resource management
>> __free() to drop the open coded put_device() and '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>
> Nice.
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huwaei.com>