Skip to content

Commit da6a6b6

Browse files
committed
rbd: fix error handling from rbd_snap_name()
rbd_snap_name() calls rbd_dev_v{1,2}_snap_name() depending on the format of the image. The format 1 version returns NULL on error, which is handled by the caller. The format 2 version returns an ERR_PTR, which the caller of rbd_snap_name() does not expect. Fortunately this is unlikely to occur in practice because rbd_snap_id_by_name() is called before rbd_snap_name(). This would hit similar errors to rbd_snap_name() (like the snapshot not existing) and return early, so rbd_snap_name() would not hit an error unless the snapshot was removed between the two calls or memory was exhausted. Use an ERR_PTR in rbd_dev_v1_snap_name() so that the specific error can be propagated, and it is consistent with rbd_dev_v2_snap_name(). Handle the ERR_PTR in the only rbd_snap_name() caller. Suggested-by: Alex Elder <[email protected]> Signed-off-by: Josh Durgin <[email protected]> Reviewed-by: Alex Elder <[email protected]>
1 parent efadc98 commit da6a6b6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/block/rbd.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,12 +927,14 @@ static const char *rbd_dev_v1_snap_name(struct rbd_device *rbd_dev,
927927
u64 snap_id)
928928
{
929929
u32 which;
930+
const char *snap_name;
930931

931932
which = rbd_dev_snap_index(rbd_dev, snap_id);
932933
if (which == BAD_SNAP_INDEX)
933-
return NULL;
934+
return ERR_PTR(-ENOENT);
934935

935-
return _rbd_dev_v1_snap_name(rbd_dev, which);
936+
snap_name = _rbd_dev_v1_snap_name(rbd_dev, which);
937+
return snap_name ? snap_name : ERR_PTR(-ENOMEM);
936938
}
937939

938940
static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id)
@@ -4163,8 +4165,8 @@ static int rbd_dev_spec_update(struct rbd_device *rbd_dev)
41634165
/* Look up the snapshot name, and make a copy */
41644166

41654167
snap_name = rbd_snap_name(rbd_dev, spec->snap_id);
4166-
if (!snap_name) {
4167-
ret = -ENOMEM;
4168+
if (IS_ERR(snap_name)) {
4169+
ret = PTR_ERR(snap_name);
41684170
goto out_err;
41694171
}
41704172

0 commit comments

Comments
 (0)