Message ID | 20171201024110.23028-1-sjitindarsingh@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | external/pflash: Fix non-zero return code for successful read when size%256 != 0 | expand |
On Fri, 2017-12-01 at 13:41 +1100, Suraj Jitindar Singh wrote: > When performing a read the return value from pflash is non-zero, even for > a successful read, when the size being read is not a multiple of 256. > This is because do_read_file returns the value from the write system > call which is then returned by pflash. When the size is a multiple of > 256 we get lucky in that this wraps around back to zero. However for any > other value the return code is size % 256. This means even when the > operation is successful the return code will seem to reflect an error. > > Fix this by returning zero if the entire size was read correctly, > otherwise return the corresponding error code. > > Fixes: e1cf130d ("external/pflash: Remove use of exit() and fix memory leaks") > > Reported-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com> > Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> Reviewed-by: Cyril Bur <cyrilbur@gmail.com> > --- > external/pflash/pflash.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c > index 381df24f..a5e7bc35 100644 > --- a/external/pflash/pflash.c > +++ b/external/pflash/pflash.c > @@ -511,7 +511,7 @@ static int do_read_file(struct blocklevel_device *bl, const char *file, > } > progress_end(); > close(fd); > - return rc; > + return size ? rc : 0; > } > > static int enable_4B_addresses(struct blocklevel_device *bl)
On Fri, 2017-12-01 at 13:41 +1100, Suraj Jitindar Singh wrote: > When performing a read the return value from pflash is non-zero, even for > a successful read, when the size being read is not a multiple of 256. > This is because do_read_file returns the value from the write system > call which is then returned by pflash. When the size is a multiple of > 256 we get lucky in that this wraps around back to zero. However for any > other value the return code is size % 256. This means even when the > operation is successful the return code will seem to reflect an error. > > Fix this by returning zero if the entire size was read correctly, > otherwise return the corresponding error code. > > Fixes: e1cf130d ("external/pflash: Remove use of exit() and fix memory leaks") > > Reported-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com> > Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> Reviewed-by: Cyril Bur <cyrilbur@gmail.com> > --- > external/pflash/pflash.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c > index 381df24f..a5e7bc35 100644 > --- a/external/pflash/pflash.c > +++ b/external/pflash/pflash.c > @@ -511,7 +511,7 @@ static int do_read_file(struct blocklevel_device *bl, const char *file, > } > progress_end(); > close(fd); > - return rc; > + return size ? rc : 0; > } > > static int enable_4B_addresses(struct blocklevel_device *bl) <div dir="ltr"><div bgcolor="#252a2c" text="#919494" link="#215d9c" vlink="#919494" style="word-wrap:break-word;line-break:after-white-space"><pre><span id="m_-1726879403395484516-x-evo-selection-start-marker"></span><span id="m_-1726879403395484516-x-evo-selection-end-marker"></span>On Fri, 2017-12-01 at 13:41 +1100, Suraj Jitindar Singh wrote:</pre><blockquote type="cite"><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>When performing a read the return value from pflash is non-zero, even for</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>a successful read, when the size being read is not a multiple of 256.</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>This is because do_read_file returns the value from the write system</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>call which is then returned by pflash. When the size is a multiple of</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>256 we get lucky in that this wraps around back to zero. However for any</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>other value the return code is size % 256. This means even when the</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>operation is successful the return code will seem to reflect an error.</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span><br></pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>Fix this by returning zero if the entire size was read correctly,</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>otherwise return the corresponding error code.</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span><br></pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>Fixes: e1cf130d ("external/pflash: Remove use of exit() and fix memory leaks")</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span><br></pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>Reported-by: Pridhiviraj Paidipeddi <<a href="mailto:ppaidipe@linux.vnet.ibm.com" target="_blank">ppaidipe@linux.vnet.ibm.com</a>></pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>Signed-off-by: Suraj Jitindar Singh <<a href="mailto:sjitindarsingh@gmail.com" target="_blank">sjitindarsingh@gmail.com</a>></pre></blockquote><pre><br></pre><pre>Reviewed-by: Cyril Bur <<a href="mailto:cyrilbur@gmail.com" target="_blank">cyrilbur@gmail.com</a>></pre><pre><br></pre><blockquote type="cite"><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>---</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> external/pflash/pflash.c | 2 +-</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> 1 file changed, 1 insertion(+), 1 deletion(-)</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span><br></pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>index 381df24f..a5e7bc35 100644</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>--- a/external/pflash/pflash.c</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>+++ b/external/pflash/pflash.c</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>@@ -511,7 +511,7 @@ static int do_read_file(struct blocklevel_device *bl, const char *file,</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> <span class="m_-1726879403395484516Apple-tab-span" style="white-space:pre-wrap"> </span>}</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> <span class="m_-1726879403395484516Apple-tab-span" style="white-space:pre-wrap"> </span>progress_end();</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> <span class="m_-1726879403395484516Apple-tab-span" style="white-space:pre-wrap"> </span>close(fd);</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>-<span class="m_-1726879403395484516Apple-tab-span" style="white-space:pre-wrap"> </span>return rc;</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span>+<span class="m_-1726879403395484516Apple-tab-span" style="white-space:pre-wrap"> </span>return size ? rc : 0;</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> }</pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> </pre><pre><span class="m_-1726879403395484516-x-evo-quoted"><span class="m_-1726879403395484516-x-evo-quote-character">> </span></span> static int enable_4B_addresses(struct blocklevel_device *bl)</pre></blockquote><div class="m_-1726879403395484516-x-evo-signature-wrapper"><span class="m_-1726879403395484516-x-evo-signature" id="m_-1726879403395484516none"></span></div></div></div>
Suraj Jitindar Singh <sjitindarsingh@gmail.com> writes: > When performing a read the return value from pflash is non-zero, even for > a successful read, when the size being read is not a multiple of 256. > This is because do_read_file returns the value from the write system > call which is then returned by pflash. When the size is a multiple of > 256 we get lucky in that this wraps around back to zero. However for any > other value the return code is size % 256. This means even when the > operation is successful the return code will seem to reflect an error. > > Fix this by returning zero if the entire size was read correctly, > otherwise return the corresponding error code. > > Fixes: e1cf130d ("external/pflash: Remove use of exit() and fix memory leaks") > > Reported-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com> > Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> > --- > external/pflash/pflash.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Merged to master as of 535d86ee98935793c0a03eb0ced6b206ce04825c
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 381df24f..a5e7bc35 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -511,7 +511,7 @@ static int do_read_file(struct blocklevel_device *bl, const char *file, } progress_end(); close(fd); - return rc; + return size ? rc : 0; } static int enable_4B_addresses(struct blocklevel_device *bl)
When performing a read the return value from pflash is non-zero, even for a successful read, when the size being read is not a multiple of 256. This is because do_read_file returns the value from the write system call which is then returned by pflash. When the size is a multiple of 256 we get lucky in that this wraps around back to zero. However for any other value the return code is size % 256. This means even when the operation is successful the return code will seem to reflect an error. Fix this by returning zero if the entire size was read correctly, otherwise return the corresponding error code. Fixes: e1cf130d ("external/pflash: Remove use of exit() and fix memory leaks") Reported-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> --- external/pflash/pflash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)