ringbuffer: fix mistaken errno handling around _rb_chunk_reclaim

Previously, there were two separate logical issues:

- errno could be set negative in qb_rb_chunk_alloc when
  when "reclaim" notifier failed

- _rb_chunk_reclaim (note: local scoped, hence comfortable for changes)
  was already setting errno at a single (coincidentally, in a correct
  way, but that'd be overwritten with the inverse because of the
  previous logical issue in qb_rb_chunk_alloc), so make it set errno
  at each failure path (now also when internal integrity in
  _rb_chunk_reclaim failed(), sparing the callers to double on that task

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
This commit is contained in:
Jan Pokorný 2019-07-19 10:35:38 +02:00 committed by Chrissie Caulfield
parent aad74c7e39
commit 484fddddb8

View File

@ -422,8 +422,7 @@ qb_rb_chunk_alloc(struct qb_ringbuffer_s * rb, size_t len)
while (qb_rb_space_free(rb) < (len + QB_RB_CHUNK_MARGIN)) {
int rc = _rb_chunk_reclaim(rb);
if (rc != 0) {
errno = rc;
return NULL;
return NULL; /* errno already set */
}
}
} else {
@ -542,7 +541,8 @@ _rb_chunk_reclaim(struct qb_ringbuffer_s * rb)
old_read_pt = rb->shared_hdr->read_pt;
chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, old_read_pt);
if (chunk_magic != QB_RB_CHUNK_MAGIC) {
return -EINVAL;
errno = EINVAL;
return -errno;
}
old_chunk_size = QB_RB_CHUNK_SIZE_GET(rb, old_read_pt);