region: add rdev_chain_full()

Instead of open coding an offset of 0 and querying the size of a
region device provide a rdev_chain_full() helper function that
does that for the caller. For the existing users that match this pattern
convert them to using rdev_chain_full().

Change-Id: Ie316790a8a5b16a7f7e22f86f58bd2e633c19450
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/36683
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Aaron Durbin 2019-11-08 09:51:15 -07:00 committed by Patrick Georgi
parent f0564a9c44
commit b1ea53d846
4 changed files with 11 additions and 7 deletions

View File

@ -32,14 +32,13 @@ int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs,
static inline void cbfs_file_data(struct region_device *data, static inline void cbfs_file_data(struct region_device *data,
const struct cbfsf *file) const struct cbfsf *file)
{ {
rdev_chain(data, &file->data, 0, region_device_sz(&file->data)); rdev_chain_full(data, &file->data);
} }
static inline void cbfs_file_metadata(struct region_device *metadata, static inline void cbfs_file_metadata(struct region_device *metadata,
const struct cbfsf *file) const struct cbfsf *file)
{ {
rdev_chain(metadata, &file->metadata, 0, rdev_chain_full(metadata, &file->metadata);
region_device_sz(&file->metadata));
} }
/* /*

View File

@ -73,7 +73,6 @@ ssize_t rdev_eraseat(const struct region_device *rd, size_t offset,
int rdev_chain(struct region_device *child, const struct region_device *parent, int rdev_chain(struct region_device *child, const struct region_device *parent,
size_t offset, size_t size); size_t offset, size_t size);
/* A region_device operations. */ /* A region_device operations. */
struct region_device_ops { struct region_device_ops {
void *(*mmap)(const struct region_device *, size_t, size_t); void *(*mmap)(const struct region_device *, size_t, size_t);
@ -145,6 +144,13 @@ static inline void *rdev_mmap_full(const struct region_device *rd)
return rdev_mmap(rd, 0, region_device_sz(rd)); return rdev_mmap(rd, 0, region_device_sz(rd));
} }
static inline int rdev_chain_full(struct region_device *child,
const struct region_device *parent)
{
/* Chain full size of parent. */
return rdev_chain(child, parent, 0, region_device_sz(parent));
}
/* /*
* Compute relative offset of the child (c) w.r.t. the parent (p). Returns < 0 * Compute relative offset of the child (c) w.r.t. the parent (p). Returns < 0
* when child is not within the parent's region. * when child is not within the parent's region.

View File

@ -49,8 +49,7 @@ static int find_fmap_directory(struct region_device *fmrd)
cache = car_get_var_ptr(&fmap_cache); cache = car_get_var_ptr(&fmap_cache);
if (region_device_sz(&cache->rdev)) if (region_device_sz(&cache->rdev))
return rdev_chain(fmrd, &cache->rdev, 0, return rdev_chain_full(fmrd, &cache->rdev);
region_device_sz(&cache->rdev));
} }
boot_device_init(); boot_device_init();

View File

@ -208,7 +208,7 @@ int region_file_init(struct region_file *f, const struct region_device *p)
f->slot = RF_FATAL; f->slot = RF_FATAL;
/* Keep parent around for accessing data later. */ /* Keep parent around for accessing data later. */
if (rdev_chain(&f->rdev, p, 0, region_device_sz(p))) if (rdev_chain_full(&f->rdev, p))
return -1; return -1;
if (rdev_readat(p, &mb, 0, sizeof(mb)) < 0) { if (rdev_readat(p, &mb, 0, sizeof(mb)) < 0) {