Skip to content

Commit 3e6d704

Browse files
LiBaokun96brauner
authored andcommitted
cachefiles: remove err_put_fd label in cachefiles_ondemand_daemon_read()
The err_put_fd label is only used once, so remove it to make the code more readable. In addition, the logic for deleting error request and CLOSE request is merged to simplify the code. Signed-off-by: Baokun Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Jeff Layton <[email protected]> Reviewed-by: Jia Zhu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Jingbo Xu <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent da4a827 commit 3e6d704

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

fs/cachefiles/ondemand.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
305305
{
306306
struct cachefiles_req *req;
307307
struct cachefiles_msg *msg;
308-
unsigned long id = 0;
309308
size_t n;
310309
int ret = 0;
311310
XA_STATE(xas, &cache->reqs, cache->req_id_next);
@@ -340,49 +339,37 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
340339
cachefiles_grab_object(req->object, cachefiles_obj_get_read_req);
341340
xa_unlock(&cache->reqs);
342341

343-
id = xas.xa_index;
344-
345342
if (msg->opcode == CACHEFILES_OP_OPEN) {
346343
ret = cachefiles_ondemand_get_fd(req);
347344
if (ret) {
348345
cachefiles_ondemand_set_object_close(req->object);
349-
goto error;
346+
goto out;
350347
}
351348
}
352349

353-
msg->msg_id = id;
350+
msg->msg_id = xas.xa_index;
354351
msg->object_id = req->object->ondemand->ondemand_id;
355352

356353
if (copy_to_user(_buffer, msg, n) != 0) {
357354
ret = -EFAULT;
358-
goto err_put_fd;
359-
}
360-
361-
cachefiles_put_object(req->object, cachefiles_obj_put_read_req);
362-
/* CLOSE request has no reply */
363-
if (msg->opcode == CACHEFILES_OP_CLOSE) {
364-
xa_erase(&cache->reqs, id);
365-
complete(&req->done);
355+
if (msg->opcode == CACHEFILES_OP_OPEN)
356+
close_fd(((struct cachefiles_open *)msg->data)->fd);
366357
}
367-
368-
cachefiles_req_put(req);
369-
return n;
370-
371-
err_put_fd:
372-
if (msg->opcode == CACHEFILES_OP_OPEN)
373-
close_fd(((struct cachefiles_open *)msg->data)->fd);
374-
error:
358+
out:
375359
cachefiles_put_object(req->object, cachefiles_obj_put_read_req);
376-
xas_reset(&xas);
377-
xas_lock(&xas);
378-
if (xas_load(&xas) == req) {
379-
req->error = ret;
380-
complete(&req->done);
381-
xas_store(&xas, NULL);
360+
/* Remove error request and CLOSE request has no reply */
361+
if (ret || msg->opcode == CACHEFILES_OP_CLOSE) {
362+
xas_reset(&xas);
363+
xas_lock(&xas);
364+
if (xas_load(&xas) == req) {
365+
req->error = ret;
366+
complete(&req->done);
367+
xas_store(&xas, NULL);
368+
}
369+
xas_unlock(&xas);
382370
}
383-
xas_unlock(&xas);
384371
cachefiles_req_put(req);
385-
return ret;
372+
return ret ? ret : n;
386373
}
387374

388375
typedef int (*init_req_fn)(struct cachefiles_req *req, void *private);

0 commit comments

Comments
 (0)