Commit c875c76a authored by David Howells's avatar David Howells

afs: Fix a Sparse warning in xdr_decode_AFSFetchStatus()

Sparse doesn't appear able to handle the conditionally-taken locks in
xdr_decode_AFSFetchStatus(), even though the lock and unlock are both
contingent on the same unvarying function argument.

Deal with this by interpolating a wrapper function that takes the lock if
needed and calls xdr_decode_AFSFetchStatus() on two separate branches, one
with the lock held and one without.

This allows Sparse to work out the locking.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 564def71
...@@ -137,10 +137,6 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call, ...@@ -137,10 +137,6 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call,
u64 data_version, size; u64 data_version, size;
u32 type, abort_code; u32 type, abort_code;
u8 flags = 0; u8 flags = 0;
int ret;
if (vnode)
write_seqlock(&vnode->cb_lock);
if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) { if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version)); pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
...@@ -168,8 +164,7 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call, ...@@ -168,8 +164,7 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call,
case AFS_FTYPE_INVALID: case AFS_FTYPE_INVALID:
if (abort_code != 0) { if (abort_code != 0) {
status->abort_code = abort_code; status->abort_code = abort_code;
ret = 0; return 0;
goto out;
} }
/* Fall through */ /* Fall through */
default: default:
...@@ -222,17 +217,35 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call, ...@@ -222,17 +217,35 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call,
flags); flags);
} }
ret = 0; return 0;
out:
if (vnode)
write_sequnlock(&vnode->cb_lock);
return ret;
bad: bad:
xdr_dump_bad(*_bp); xdr_dump_bad(*_bp);
ret = afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
goto out; }
/*
* Decode the file status. We need to lock the target vnode if we're going to
* update its status so that stat() sees the attributes update atomically.
*/
static int afs_decode_status(struct afs_call *call,
const __be32 **_bp,
struct afs_file_status *status,
struct afs_vnode *vnode,
const afs_dataversion_t *expected_version,
struct afs_read *read_req)
{
int ret;
if (!vnode)
return xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
expected_version, read_req);
write_seqlock(&vnode->cb_lock);
ret = xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
expected_version, read_req);
write_sequnlock(&vnode->cb_lock);
return ret;
} }
/* /*
...@@ -374,8 +387,8 @@ static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call) ...@@ -374,8 +387,8 @@ static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, if (afs_decode_status(call, &bp, &vnode->status, vnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
xdr_decode_AFSCallBack(call, vnode, &bp); xdr_decode_AFSCallBack(call, vnode, &bp);
if (call->reply[1]) if (call->reply[1])
...@@ -555,8 +568,8 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call) ...@@ -555,8 +568,8 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)
return ret; return ret;
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, if (afs_decode_status(call, &bp, &vnode->status, vnode,
&vnode->status.data_version, req) < 0) &vnode->status.data_version, req) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
xdr_decode_AFSCallBack(call, vnode, &bp); xdr_decode_AFSCallBack(call, vnode, &bp);
if (call->reply[1]) if (call->reply[1])
...@@ -708,9 +721,9 @@ static int afs_deliver_fs_create_vnode(struct afs_call *call) ...@@ -708,9 +721,9 @@ static int afs_deliver_fs_create_vnode(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
xdr_decode_AFSFid(&bp, call->reply[1]); xdr_decode_AFSFid(&bp, call->reply[1]);
if (xdr_decode_AFSFetchStatus(call, &bp, call->reply[2], NULL, NULL, NULL) < 0 || if (afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL) < 0 ||
xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, afs_decode_status(call, &bp, &vnode->status, vnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
xdr_decode_AFSCallBack_raw(&bp, call->reply[3]); xdr_decode_AFSCallBack_raw(&bp, call->reply[3]);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -814,8 +827,8 @@ static int afs_deliver_fs_remove(struct afs_call *call) ...@@ -814,8 +827,8 @@ static int afs_deliver_fs_remove(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, if (afs_decode_status(call, &bp, &vnode->status, vnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -904,9 +917,9 @@ static int afs_deliver_fs_link(struct afs_call *call) ...@@ -904,9 +917,9 @@ static int afs_deliver_fs_link(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, NULL, NULL) < 0 || if (afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL) < 0 ||
xdr_decode_AFSFetchStatus(call, &bp, &dvnode->status, dvnode, afs_decode_status(call, &bp, &dvnode->status, dvnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -991,9 +1004,9 @@ static int afs_deliver_fs_symlink(struct afs_call *call) ...@@ -991,9 +1004,9 @@ static int afs_deliver_fs_symlink(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
xdr_decode_AFSFid(&bp, call->reply[1]); xdr_decode_AFSFid(&bp, call->reply[1]);
if (xdr_decode_AFSFetchStatus(call, &bp, call->reply[2], NULL, NULL, NULL) || if (afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL) ||
xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, afs_decode_status(call, &bp, &vnode->status, vnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -1097,12 +1110,12 @@ static int afs_deliver_fs_rename(struct afs_call *call) ...@@ -1097,12 +1110,12 @@ static int afs_deliver_fs_rename(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &orig_dvnode->status, orig_dvnode, if (afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
if (new_dvnode != orig_dvnode && if (new_dvnode != orig_dvnode &&
xdr_decode_AFSFetchStatus(call, &bp, &new_dvnode->status, new_dvnode, afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
&call->expected_version_2, NULL) < 0) &call->expected_version_2, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -1206,8 +1219,8 @@ static int afs_deliver_fs_store_data(struct afs_call *call) ...@@ -1206,8 +1219,8 @@ static int afs_deliver_fs_store_data(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, if (afs_decode_status(call, &bp, &vnode->status, vnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -1382,8 +1395,8 @@ static int afs_deliver_fs_store_status(struct afs_call *call) ...@@ -1382,8 +1395,8 @@ static int afs_deliver_fs_store_status(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
if (xdr_decode_AFSFetchStatus(call, &bp, &vnode->status, vnode, if (afs_decode_status(call, &bp, &vnode->status, vnode,
&call->expected_version, NULL) < 0) &call->expected_version, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */ /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
...@@ -2084,8 +2097,8 @@ static int afs_deliver_fs_fetch_status(struct afs_call *call) ...@@ -2084,8 +2097,8 @@ static int afs_deliver_fs_fetch_status(struct afs_call *call)
/* unmarshall the reply once we've received all of it */ /* unmarshall the reply once we've received all of it */
bp = call->buffer; bp = call->buffer;
xdr_decode_AFSFetchStatus(call, &bp, status, vnode, afs_decode_status(call, &bp, status, vnode,
&call->expected_version, NULL); &call->expected_version, NULL);
callback[call->count].version = ntohl(bp[0]); callback[call->count].version = ntohl(bp[0]);
callback[call->count].expiry = ntohl(bp[1]); callback[call->count].expiry = ntohl(bp[1]);
callback[call->count].type = ntohl(bp[2]); callback[call->count].type = ntohl(bp[2]);
...@@ -2196,9 +2209,9 @@ static int afs_deliver_fs_inline_bulk_status(struct afs_call *call) ...@@ -2196,9 +2209,9 @@ static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
bp = call->buffer; bp = call->buffer;
statuses = call->reply[1]; statuses = call->reply[1];
if (xdr_decode_AFSFetchStatus(call, &bp, &statuses[call->count], if (afs_decode_status(call, &bp, &statuses[call->count],
call->count == 0 ? vnode : NULL, call->count == 0 ? vnode : NULL,
NULL, NULL) < 0) NULL, NULL) < 0)
return afs_protocol_error(call, -EBADMSG); return afs_protocol_error(call, -EBADMSG);
call->count++; call->count++;
......
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