Commit 2c09d144 authored by Dan Carpenter's avatar Dan Carpenter Committed by Kees Cook

pstore/zone: cleanup "rcnt" type

The info->read() function returns ssize_t.  That means that info->read()
either returns either negative error codes or a positive number
representing the bytes read.

The "rcnt" variable should be declared as ssize_t as well.  Most places
do this correctly but psz_kmsg_recover_meta() needed to be fixed.

This code casts the "rcnt" to int.  That is unnecessary when "rcnt"
is already signed.  It's also slightly wrong because if info->read()
returned a very high (more than INT_MAX) number of bytes then this might
treat that as an error.  This bug cannot happen in real life, so it
doesn't affect run time, but static checkers correctly complain that it
is wrong.

fs/pstore/zone.c:366 psz_kmsg_recover_data() warn: casting 'rcnt' truncates high bits
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/YrRtPSFHDVJzV6d+@kili
parent e4f0a7ec
...@@ -363,7 +363,7 @@ static int psz_kmsg_recover_data(struct psz_context *cxt) ...@@ -363,7 +363,7 @@ static int psz_kmsg_recover_data(struct psz_context *cxt)
rcnt = info->read((char *)buf, zone->buffer_size + sizeof(*buf), rcnt = info->read((char *)buf, zone->buffer_size + sizeof(*buf),
zone->off); zone->off);
if (rcnt != zone->buffer_size + sizeof(*buf)) if (rcnt != zone->buffer_size + sizeof(*buf))
return (int)rcnt < 0 ? (int)rcnt : -EIO; return rcnt < 0 ? rcnt : -EIO;
} }
return 0; return 0;
} }
...@@ -372,7 +372,7 @@ static int psz_kmsg_recover_meta(struct psz_context *cxt) ...@@ -372,7 +372,7 @@ static int psz_kmsg_recover_meta(struct psz_context *cxt)
{ {
struct pstore_zone_info *info = cxt->pstore_zone_info; struct pstore_zone_info *info = cxt->pstore_zone_info;
struct pstore_zone *zone; struct pstore_zone *zone;
size_t rcnt, len; ssize_t rcnt, len;
struct psz_buffer *buf; struct psz_buffer *buf;
struct psz_kmsg_header *hdr; struct psz_kmsg_header *hdr;
struct timespec64 time = { }; struct timespec64 time = { };
...@@ -400,7 +400,7 @@ static int psz_kmsg_recover_meta(struct psz_context *cxt) ...@@ -400,7 +400,7 @@ static int psz_kmsg_recover_meta(struct psz_context *cxt)
continue; continue;
} else if (rcnt != len) { } else if (rcnt != len) {
pr_err("read %s with id %lu failed\n", zone->name, i); pr_err("read %s with id %lu failed\n", zone->name, i);
return (int)rcnt < 0 ? (int)rcnt : -EIO; return rcnt < 0 ? rcnt : -EIO;
} }
if (buf->sig != zone->buffer->sig) { if (buf->sig != zone->buffer->sig) {
...@@ -502,7 +502,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone) ...@@ -502,7 +502,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
rcnt = info->read((char *)&tmpbuf, len, zone->off); rcnt = info->read((char *)&tmpbuf, len, zone->off);
if (rcnt != len) { if (rcnt != len) {
pr_debug("read zone %s failed\n", zone->name); pr_debug("read zone %s failed\n", zone->name);
return (int)rcnt < 0 ? (int)rcnt : -EIO; return rcnt < 0 ? rcnt : -EIO;
} }
if (tmpbuf.sig != zone->buffer->sig) { if (tmpbuf.sig != zone->buffer->sig) {
...@@ -544,7 +544,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone) ...@@ -544,7 +544,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
rcnt = info->read(buf, len - start, off + start); rcnt = info->read(buf, len - start, off + start);
if (rcnt != len - start) { if (rcnt != len - start) {
pr_err("read zone %s failed\n", zone->name); pr_err("read zone %s failed\n", zone->name);
ret = (int)rcnt < 0 ? (int)rcnt : -EIO; ret = rcnt < 0 ? rcnt : -EIO;
goto free_oldbuf; goto free_oldbuf;
} }
...@@ -552,7 +552,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone) ...@@ -552,7 +552,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
rcnt = info->read(buf + len - start, start, off); rcnt = info->read(buf + len - start, start, off);
if (rcnt != start) { if (rcnt != start) {
pr_err("read zone %s failed\n", zone->name); pr_err("read zone %s failed\n", zone->name);
ret = (int)rcnt < 0 ? (int)rcnt : -EIO; ret = rcnt < 0 ? rcnt : -EIO;
goto free_oldbuf; goto free_oldbuf;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment