Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: ralf@linux-mips.org
Cc: linux-mips@linux-mips.org
Subject: [bug report] [MIPS] Sibyte: Fix ZBbus profiler
Date: Wed, 7 Dec 2016 22:58:20 +0300	[thread overview]
Message-ID: <20161207195820.GA17588@elgon.mountain> (raw)

Hello Ralf Baechle,

The patch bb9b813bb665: "[MIPS] Sibyte: Fix ZBbus profiler" from Mar
9, 2007, leads to the following static checker warning:

	arch/mips/sibyte/common/sb_tbprof.c:480 sbprof_tb_read()
	warn: maybe return -EFAULT instead of the bytes remaining?

arch/mips/sibyte/common/sb_tbprof.c
   452  static ssize_t sbprof_tb_read(struct file *filp, char *buf,
   453                                size_t size, loff_t *offp)
   454  {
   455          int cur_sample, sample_off, cur_count, sample_left;
   456          char *src;
   457          int   count   =  0;
   458          char *dest    =  buf;
   459          long  cur_off = *offp;
   460  
   461          if (!access_ok(VERIFY_WRITE, buf, size))
   462                  return -EFAULT;
   463  
   464          mutex_lock(&sbp.lock);
   465  
   466          count = 0;
   467          cur_sample = cur_off / TB_SAMPLE_SIZE;
   468          sample_off = cur_off % TB_SAMPLE_SIZE;
   469          sample_left = TB_SAMPLE_SIZE - sample_off;
   470  
   471          while (size && (cur_sample < sbp.next_tb_sample)) {
   472                  int err;
   473  
   474                  cur_count = size < sample_left ? size : sample_left;
   475                  src = (char *)(((long)sbp.sbprof_tbbuf[cur_sample])+sample_off);
   476                  err = __copy_to_user(dest, src, cur_count);
   477                  if (err) {
   478                          *offp = cur_off + cur_count - err;
   479                          mutex_unlock(&sbp.lock);
   480                          return err;

This doesn't look right.  __copy_to_user() returns the number of bytes
remaining to be copied so I think we should return either -EFAULT or
"count + cur_count - err".

   481                  }
   482                  pr_debug(DEVNAME ": read from sample %d, %d bytes\n",
   483                           cur_sample, cur_count);
   484                  size -= cur_count;
   485                  sample_left -= cur_count;
   486                  if (!sample_left) {
   487                          cur_sample++;
   488                          sample_off = 0;
   489                          sample_left = TB_SAMPLE_SIZE;
   490                  } else {
   491                          sample_off += cur_count;
   492                  }
   493                  cur_off += cur_count;
   494                  dest += cur_count;
   495                  count += cur_count;
   496          }
   497          *offp = cur_off;
   498          mutex_unlock(&sbp.lock);
   499  
   500          return count;
   501  }

regards,
dan carpenter

                 reply	other threads:[~2016-12-07 20:06 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=20161207195820.GA17588@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.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