From: chris <eklikeroomys@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devel@driverdev.osuosl.org, Frank Mori Hess <fmh6jj@gmail.com>,
Simo Koskinen <koskisoft@gmail.com>,
linux-kernel@vger.kernel.org, Ian Abbott <abbotti@mev.co.uk>
Subject: Re: [PATCH] staging: comedi: Improved readability of function comedi_nsamples_left.
Date: Sun, 10 Jun 2018 12:30:01 +0200 [thread overview]
Message-ID: <20180610103001.GA7804@kerdev> (raw)
In-Reply-To: <20180609140527.GC28854@kroah.com>
Hi Greg,
I've added changelog text to the patch below. Appreciate your
feedback!
Regards,
Chris Opperman
>8----------------------------------------------------------------------8<
Improved the readability of comedi_nsamples_left:
a) Reduced nesting by using more return calls.
b) Separated variable declarations from code.
c) Using kernel integer types.
Signed-off-by: Chris Opperman <eklikeroomys@gmail.com>
---
drivers/staging/comedi/drivers.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 9d73347..3207ae2 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -468,26 +468,25 @@ EXPORT_SYMBOL_GPL(comedi_nscans_left);
* Returns the number of samples remaining to complete the command, or the
* specified expected number of samples (@nsamples), whichever is fewer.
*/
-unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
- unsigned int nsamples)
+u32 comedi_nsamples_left(struct comedi_subdevice *s, u32 nsamples)
{
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
+ u32 scans_left;
+ u64 samples_left;
- 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 (cmd->stop_src != TRIG_COUNT)
+ return nsamples;
- if (samples_left < nsamples)
- nsamples = samples_left;
- }
+ scans_left = __comedi_nscans_left(s, cmd->stop_arg);
+ if (!scans_left)
+ return 0;
+
+ samples_left = ((u64)scans_left * cmd->scan_end_arg) -
+ comedi_bytes_to_samples(s, async->scan_progress);
+
+ if (samples_left < nsamples)
+ return samples_left;
return nsamples;
}
EXPORT_SYMBOL_GPL(comedi_nsamples_left);
--
2.1.4
next prev parent reply other threads:[~2018-06-10 8:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-09 14:23 [PATCH] staging: comedi: Improved readability of function comedi_nsamples_left Chris Opperman
2018-06-09 14:05 ` Greg Kroah-Hartman
2018-06-10 10:30 ` chris [this message]
2018-06-12 8:56 ` Dan Carpenter
2018-06-12 18:59 ` Chris Opperman
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=20180610103001.GA7804@kerdev \
--to=eklikeroomys@gmail.com \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=fmh6jj@gmail.com \
--cc=gregkh@linuxfoundation.org \
--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