mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Chris Opperman <eklikeroomys@gmail.com>
Cc: Ian Abbott <abbotti@mev.co.uk>,
	H Hartley Sweeten <hsweeten@visionengravers.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Frank Mori Hess <fmh6jj@gmail.com>,
	Simo Koskinen <koskisoft@gmail.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: comedi: shortened a long line
Date: Sat, 09 Jun 2018 02:36:31 -0700	[thread overview]
Message-ID: <86ccd1d2471b4541c2242d71173734cdbb99f247.camel@perches.com> (raw)
In-Reply-To: <1528541720-1853-1-git-send-email-eklikeroomys@gmail.com>

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);

  reply	other threads:[~2018-06-09  9:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-09 10:54 Chris Opperman
2018-06-09  9:36 ` Joe Perches [this message]
2018-06-09 13:20   ` chris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86ccd1d2471b4541c2242d71173734cdbb99f247.camel@perches.com \
    --to=joe@perches.com \
    --cc=abbotti@mev.co.uk \
    --cc=devel@driverdev.osuosl.org \
    --cc=eklikeroomys@gmail.com \
    --cc=fmh6jj@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=koskisoft@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®