public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: re: memstick: add support for legacy memorysticks
Date: Fri, 12 Feb 2016 20:45:15 +0000	[thread overview]
Message-ID: <20160212204515.GA21611@mwanda> (raw)

Hello Maxim Levitsky,

The patch 0ab30494bc4f: "memstick: add support for legacy
memorysticks" from Sep 11, 2013, leads to the following static
checker warning:

	drivers/memstick/core/ms_block.c:84 msb_sg_copy()
	warn: should this be 'to_nents = -1'

drivers/memstick/core/ms_block.c
    40  static size_t msb_sg_copy(struct scatterlist *sg_from,
    41          struct scatterlist *sg_to, int to_nents, size_t offset, size_t len)
    42  {
    43          size_t copied = 0;
    44  
    45          while (offset > 0) {
    46                  if (offset >= sg_from->length) {
    47                          if (sg_is_last(sg_from))
    48                                  return 0;
    49  
    50                          offset -= sg_from->length;
    51                          sg_from = sg_next(sg_from);
    52                          continue;
    53                  }
    54  
    55                  copied = min(len, sg_from->length - offset);
    56                  sg_set_page(sg_to, sg_page(sg_from),
    57                          copied, sg_from->offset + offset);
    58  
    59                  len -= copied;
    60                  offset = 0;
    61  
    62                  if (sg_is_last(sg_from) || !len)
    63                          goto out;
    64  
    65                  sg_to = sg_next(sg_to);
    66                  to_nents--;
                        ^^^^^^^^^^^
    67                  sg_from = sg_next(sg_from);
    68          }
    69  
    70          while (len > sg_from->length && to_nents--) {

This is a post-op so we exit with to_nents = -1.  It feels like this
should be to_nents-- >= 0 because of the earlier decremenet.  Int the
worst case that seems like a harmless change which improves readiblity.

    71                  len -= sg_from->length;
    72                  copied += sg_from->length;
    73  
    74                  sg_set_page(sg_to, sg_page(sg_from),
    75                                  sg_from->length, sg_from->offset);
    76  
    77                  if (sg_is_last(sg_from) || !len)
    78                          goto out;
    79  
    80                  sg_from = sg_next(sg_from);
    81                  sg_to = sg_next(sg_to);
    82          }
    83  
    84          if (len && to_nents) {

This looks buggy.  It should probably as well be:

		if (len && to_nents >= 0) {

    85                  sg_set_page(sg_to, sg_page(sg_from), len, sg_from->offset);
    86                  copied += len;
    87          }
    88  out:
    89          sg_mark_end(sg_to);
    90          return copied;
    91  }

regards,
dan carpenter

                 reply	other threads:[~2016-02-12 20:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20160212204515.GA21611@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@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