linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] staging: comedi: shortened a long line
  2018-06-09 10:54 [PATCH] staging: comedi: shortened a long line Chris Opperman
@ 2018-06-09  9:36 ` Joe Perches
  2018-06-09 13:20   ` chris
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2018-06-09  9:36 UTC (permalink / raw)
  To: Chris Opperman
  Cc: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman,
	Frank Mori Hess, Simo Koskinen, devel, linux-kernel

On Sat, 2018-06-09 at 12:54 +0200, Chris Opperman wrote:
> Shortened a long line to improve readability in 
> drivers/staging/comedi/drivers.c

Hi Chris.

Look at the whole function and see if you can
find a better way to write it instead of merely
doing what a brainless tool like checkpatch asks.

> diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
[]
> @@ -475,7 +475,8 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
>  	struct comedi_cmd *cmd = &async->cmd;
>  
>  	if (cmd->stop_src == TRIG_COUNT) {
> -		unsigned int scans_left = __comedi_nscans_left(s, cmd->stop_arg);
> +		unsigned int scans_left =
> +		    __comedi_nscans_left(s, cmd->stop_arg);
>  		unsigned int scan_pos =
>  		    comedi_bytes_to_samples(s, async->scan_progress);
>  		unsigned long long samples_left = 0;

For instance, this is the existing function:

unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
				  unsigned int nsamples)
{
	struct comedi_async *async = s->async;
	struct comedi_cmd *cmd = &async->cmd;

	if (cmd->stop_src == TRIG_COUNT) {
		unsigned int scans_left = __comedi_nscans_left(s, cmd->stop_arg);
		unsigned int scan_pos =
		    comedi_bytes_to_samples(s, async->scan_progress);
		unsigned long long samples_left = 0;

		if (scans_left) {
			samples_left = ((unsigned long long)scans_left *
					cmd->scan_end_arg) - scan_pos;
		}

		if (samples_left < nsamples)
			nsamples = samples_left;
	}
	return nsamples;
}
EXPORT_SYMBOL_GPL(comedi_nsamples_left);

By using multiple returns and removing indentation,
this could become something that doesn't fits
neatly on 80 columns.
It's the same number of vertical lines too.

unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
				  unsigned int nsamples)
{
	struct comedi_async *async = s->async;
	struct comedi_cmd *cmd = &async->cmd;
	unsigned int scans_left;
	u64 samples_left;

	if (cmd->stop_src != TRIG_COUNT)
		return nsamples;

	scans_left = __comedi_nscans_left(s, cmd->stop_arg);
	if (scans_left == 0)
		return 0;

	samples_left = (u64)scans_left * cmd->scan_end_arg -
			comedi_bytes_to_samples(s, s->async->scan_progress);
	if (samples_left < nsamples)
		return samples_left;

	return nsamples;
}
EXPORT_SYMBOL_GPL(comedi_nsamples_left);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] staging: comedi: shortened a long line
@ 2018-06-09 10:54 Chris Opperman
  2018-06-09  9:36 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Opperman @ 2018-06-09 10:54 UTC (permalink / raw)
  Cc: eklikeroomys, Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman,
	Frank Mori Hess, Simo Koskinen, devel, linux-kernel

Shortened a long line to improve readability in 
drivers/staging/comedi/drivers.c

Signed-off-by: Chris Opperman <eklikeroomys@gmail.com>
---
 drivers/staging/comedi/drivers.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 9d73347..90ee974 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -475,7 +475,8 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
 	struct comedi_cmd *cmd = &async->cmd;
 
 	if (cmd->stop_src == TRIG_COUNT) {
-		unsigned int scans_left = __comedi_nscans_left(s, cmd->stop_arg);
+		unsigned int scans_left =
+		    __comedi_nscans_left(s, cmd->stop_arg);
 		unsigned int scan_pos =
 		    comedi_bytes_to_samples(s, async->scan_progress);
 		unsigned long long samples_left = 0;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: comedi: shortened a long line
  2018-06-09  9:36 ` Joe Perches
@ 2018-06-09 13:20   ` chris
  0 siblings, 0 replies; 3+ messages in thread
From: chris @ 2018-06-09 13:20 UTC (permalink / raw)
  To: Joe Perches
  Cc: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman,
	Frank Mori Hess, Simo Koskinen, devel, linux-kernel

Hi Joe,

Thank you for the feedback! I understand better now and will resend
the patch.

Regards,
Chris Opperman

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-09 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-09 10:54 [PATCH] staging: comedi: shortened a long line Chris Opperman
2018-06-09  9:36 ` Joe Perches
2018-06-09 13:20   ` chris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).