lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 17 Apr 2020 10:32:07 -0700
From:   Joe Perches <joe@...ches.com>
To:     Luben Tuikov <luben.tuikov@....com>,
        Andy Whitcroft <apw@...onical.com>
Cc:     LKML <linux-kernel@...r.kernel.org>
Subject: Re: checkpatch.pl warning for "return" with value

On Fri, 2020-04-17 at 13:20 -0400, Luben Tuikov wrote:
> Hi guys,
> 
> I get this warning:
> 
> :32: WARNING: else is not generally useful after a break or return
> #32: FILE: drivers/gpu/drm/amd/amdgpu/amdgpu_job.c:55:
> +		return 0;
> +	} else {
> 
> for the following code, at the bottom of a function:
> 
> 	if (amdgpu_device_should_recover_gpu(ring->adev)) {
> 		amdgpu_device_gpu_recover(ring->adev, job);
> 		return 0;
> 	} else {
> 		drm_sched_suspend_timeout(&ring->sched);
> 		return 1;
> 	}
> }
> 
> It seems like a false positive--I mean, if the else branch was
> taken, we'd return a different result.

There is an existing checkpatch exception for single line
if/else returns
like:

	if (foo)
		return bar;
	else
		return baz;

because that's a pretty common code style.

But I personally don't think that your example fits the
same style.

I think when unexpected condition should be separated from
the expected condition which should typically be the last
block of a function like:


	if (<atypical_condition>) {
		...;
		return <atypical_result>;
	}

	...;
	return <typical_result>;
}

If you want to code it, and it works, go ahead, but I
won't attempt it because I think it's not appropriate.

cheers, Joe

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ