Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp103446lqp; Tue, 21 May 2024 20:52:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDZ0zvA6tO9PlfLej2CxCYsmv/Lk9q2U4LAAmc6sQYC1gy/3sek+IL7qJ1AMFithdA+xjHF6ZFu45vgKr2gnJWIhp1/6ie5IkQaFy2WQ== X-Google-Smtp-Source: AGHT+IGcI2nH/u5Y4TKlEq1BMdjWohKihSRZZibRiXZ0y6YbQylUCl7CQ4FrumMGRnm1QM+CCBY2 X-Received: by 2002:ae9:f809:0:b0:792:dbc4:23b6 with SMTP id af79cd13be357-79499441bd3mr80669485a.22.1716349953244; Tue, 21 May 2024 20:52:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716349953; cv=pass; d=google.com; s=arc-20160816; b=LlS6zPZsrPR1jxc3NvXKwbdMQpwIssjsZYQuDHpqQ/GfSXN9Em29flkI9/y/0kOqJG hXPTABRh+x9eiOaoB1zegOzmiv8/fTOtpUxktJ+HvAiw2QroJv2o3V0OIMopOsxvg/P/ v28PEDDqgy1ECo2f8QC/2V3FWyqYRoOB2TdGCyHSXkfc1gv5SluQ9SZt0QIZ7GCVWDgB 03B90ua1hTQzGtF7j27FmvGGRD6s+IrjukX/OJuPritr9mOEWL0XBJxZRmpOWCtgjZwu 435yFb5+CloSyUeyEDeqE6QoIteFIUh77I8eHays/jpkBFQk35WRluROLDb/1xZY7IKL 6Kvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xzVDQ/ll0jbo1a31unV06eKX9kcmDFcq2ZPF1MeKlII=; fh=dfpuzL54LAMf7GQmHoqmub+qZCPWKUPNTVFHnj8Vxqk=; b=J9bd+oWAR99/izdLqYmR8KWV99AS/0V2K/2ZbnLv/FMMu8AsctuiyeY4ijlnPWyf6a 57H6GignhsURlFC3/6a5i8ktlxFycoShu/Polxs0ZOU7imkVc0D9cXwy0OJIKiK8l65B v0GDj9D0oYTyeoJ8ZopWFufj4kBDp28KKjol8j6UPDdC9ySuJwM+Gv4RMM7m4j8gwSUR O3+QVJKAzhdeWNniZoa98K/N9MEDYt/j3fGW4gplV31TobdTnndDW5NWMZ3aUcyKqmEk rTPQaUz1svABV9OJafGFCJ9/70k+Pi5O4jLBlvHjFOoIIGcqRzG3MbuLvPLf7pPCjwdy NRtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-185743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185743-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-79483d833d5si465994585a.517.2024.05.21.20.52.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 20:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-185743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185743-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E6A741C2171E for ; Wed, 22 May 2024 03:52:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52F2E80043; Wed, 22 May 2024 03:50:09 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D9417C086; Wed, 22 May 2024 03:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716349808; cv=none; b=Wtn0nfDIQWnlXXo42ZlfoFsb8b0/d6XcJohwmGmum1Pq8ccDDYq/gjy+bp81RQWVo8XNioNzTl8Cc6g6rHCXZC52dtcN8usOC3uDkuRZwTJjwAP7NG4I/y5gERPbbqg28X+VNqL1WGppq0hItWcjyPFB15JaDggbjNJvbHeVo4w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716349808; c=relaxed/simple; bh=1VesqAjR/ithgpkYnQ975NMfRqNMygcAMQValyCxEOQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C79ggls996lwg1uqHl+iEqew260ZIb6vRWHvsI+xJYBy8RDsDqw47lGw23wqWQnuLK9RgDNFgO5M7WaTl4jJB5gjW0nERlZKujYyzZrM8/5GLxhmBh723SX2+1gq5XdJA6dQi7IxjV78qOGzdioSNws3ys+e2+Mm1zMmP8cLUDE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vkckl6HXRz4f3jkP; Wed, 22 May 2024 11:49:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A565A1A016E; Wed, 22 May 2024 11:49:57 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBFea01mxlBXNQ--.57627S9; Wed, 22 May 2024 11:49:57 +0800 (CST) From: libaokun@huaweicloud.com To: netfs@lists.linux.dev, dhowells@redhat.com, jlayton@kernel.org Cc: hsiangkao@linux.alibaba.com, jefflexu@linux.alibaba.com, zhujia.zj@bytedance.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libaokun@huaweicloud.com, yangerkun@huawei.com, houtao1@huawei.com, yukuai3@huawei.com, wozizhi@huawei.com, Baokun Li Subject: [PATCH v3 05/12] cachefiles: remove err_put_fd label in cachefiles_ondemand_daemon_read() Date: Wed, 22 May 2024 19:43:01 +0800 Message-Id: <20240522114308.2402121-6-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522114308.2402121-1-libaokun@huaweicloud.com> References: <20240522114308.2402121-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBHGBFea01mxlBXNQ--.57627S9 X-Coremail-Antispam: 1UD129KBjvJXoWxZrW3ArWDtw1kKF18Jr1kKrg_yoW5Wr43pF WSyay7Kry8WF48Crn7A3W5X34rt3y8Z3ZrW3y0qw1fArnIqr15Zr18tF15ZFy5ArWvgrsx tw18CFZrGryjq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7sREMKZDUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/ From: Baokun Li 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 Acked-by: Jeff Layton Reviewed-by: Jia Zhu Reviewed-by: Gao Xiang --- fs/cachefiles/ondemand.c | 45 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 3dd002108a87..bb94ef6a6f61 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -305,7 +305,6 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, { struct cachefiles_req *req; struct cachefiles_msg *msg; - unsigned long id = 0; size_t n; int ret = 0; XA_STATE(xas, &cache->reqs, cache->req_id_next); @@ -340,49 +339,37 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, cachefiles_grab_object(req->object, cachefiles_obj_get_read_req); xa_unlock(&cache->reqs); - id = xas.xa_index; - if (msg->opcode == CACHEFILES_OP_OPEN) { ret = cachefiles_ondemand_get_fd(req); if (ret) { cachefiles_ondemand_set_object_close(req->object); - goto error; + goto out; } } - msg->msg_id = id; + msg->msg_id = xas.xa_index; msg->object_id = req->object->ondemand->ondemand_id; if (copy_to_user(_buffer, msg, n) != 0) { ret = -EFAULT; - goto err_put_fd; - } - - cachefiles_put_object(req->object, cachefiles_obj_put_read_req); - /* CLOSE request has no reply */ - if (msg->opcode == CACHEFILES_OP_CLOSE) { - xa_erase(&cache->reqs, id); - complete(&req->done); + if (msg->opcode == CACHEFILES_OP_OPEN) + close_fd(((struct cachefiles_open *)msg->data)->fd); } - - cachefiles_req_put(req); - return n; - -err_put_fd: - if (msg->opcode == CACHEFILES_OP_OPEN) - close_fd(((struct cachefiles_open *)msg->data)->fd); -error: +out: cachefiles_put_object(req->object, cachefiles_obj_put_read_req); - xas_reset(&xas); - xas_lock(&xas); - if (xas_load(&xas) == req) { - req->error = ret; - complete(&req->done); - xas_store(&xas, NULL); + /* Remove error request and CLOSE request has no reply */ + if (ret || msg->opcode == CACHEFILES_OP_CLOSE) { + xas_reset(&xas); + xas_lock(&xas); + if (xas_load(&xas) == req) { + req->error = ret; + complete(&req->done); + xas_store(&xas, NULL); + } + xas_unlock(&xas); } - xas_unlock(&xas); cachefiles_req_put(req); - return ret; + return ret ? ret : n; } typedef int (*init_req_fn)(struct cachefiles_req *req, void *private); -- 2.39.2