Re: [PATCH] Sony-laptop: Use common error handling code in sony_nc_setup_rfkill()

From: Andy Shevchenko
Date: Tue Oct 31 2017 - 09:33:26 EST


On Mon, Oct 30, 2017 at 10:15 PM, SF Markus Elfring
<elfring@xxxxxxxxxxxxxxxxxxxxx> wrote:
> From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> Date: Mon, 30 Oct 2017 21:10:49 +0100
>
> Add a jump target so that a bit of exception handling can be better reused
> at the end of this function.
>
> This issue was detected by using the Coccinelle software.

Apparently this patch done without reading the actual code.

NAK.

-1 is EPERM which sounds wrong here. If you would like to fix it,
propagate a real error codes from sony_call_snc_handle().

> if (!rfk)
> return -ENOMEM;

Okay error code.

>
> - if (sony_call_snc_handle(sony_rfkill_handle, 0x200, &result) < 0) {
> - rfkill_destroy(rfk);
> - return -1;

Not okay.

> - }
> + if (sony_call_snc_handle(sony_rfkill_handle, 0x200, &result) < 0)
> + goto destroy_rfk;
> +
> hwblock = !(result & 0x1);
>
> if (sony_call_snc_handle(sony_rfkill_handle,
> - sony_rfkill_address[nc_type],
> - &result) < 0) {
> - rfkill_destroy(rfk);
> - return -1;

Not okay and it might be different from previous case.

> - }
> + sony_rfkill_address[nc_type],
> + &result) < 0)
> + goto destroy_rfk;
> +
> swblock = !(result & 0x2);
>
> rfkill_init_sw_state(rfk, swblock);
> @@ -1684,6 +1682,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> }
> sony_rfkill_devices[nc_type] = rfk;
> return err;
> +
> +destroy_rfk:
> + rfkill_destroy(rfk);
> + return -1;

P.S. Don't bother us with patches on which you didn't do your home work.
Thanks for understanding.

--
With Best Regards,
Andy Shevchenko