From patchwork Fri Jun 10 09:07:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12877051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BED5C433EF for ; Fri, 10 Jun 2022 09:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243365AbiFJJKj (ORCPT ); Fri, 10 Jun 2022 05:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343938AbiFJJJ7 (ORCPT ); Fri, 10 Jun 2022 05:09:59 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9BD91E82A0 for ; Fri, 10 Jun 2022 02:07:49 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1654852068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L1wIvv3zLWMR31Nd8s1DbvuiWn532QeRZmT5/FrvJdE=; b=q5Y/70HuwnuIfNaffHMJEThg1cRW9iR3ImdgDhw+Tw3h88zt9AKhDchdXxxJIq7J5Cuggf Skjp2AtP5iiKmVrmk3y0gp9c6vAOFPPdjkiORZLM8TChLDtTBfOeV1Ev6mVba1cqVgGbTf oW2kDCtQKw1cWmIvR+9hM+s2pKmYCs4= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 2/5] io_uring: openclose: fix bug of unexpected return value in IORING_CLOSE_FD_AND_FILE_SLOT mode Date: Fri, 10 Jun 2022 17:07:31 +0800 Message-Id: <20220610090734.857067-3-hao.xu@linux.dev> In-Reply-To: <20220610090734.857067-1-hao.xu@linux.dev> References: <20220610090734.857067-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu In IORING_CLOSE_FD_AND_FILE_SLOT mode, if we successfully close fixed file but fails in close->fd >= fdt->max_fds check, cqe-res = 0 is returned, which should be -EBADF. Fixes: a7c41b4687f5 ("io_uring: let IORING_OP_FILES_UPDATE support choosing fixed file slots") Signed-off-by: Hao Xu --- io_uring/openclose.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/io_uring/openclose.c b/io_uring/openclose.c index b35bf5f66dd9..4eb1f23e028a 100644 --- a/io_uring/openclose.c +++ b/io_uring/openclose.c @@ -248,7 +248,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) struct io_close *close = io_kiocb_to_cmd(req); struct fdtable *fdt; struct file *file; - int ret = -EBADF; + int ret; if (close->file_slot) { ret = io_close_fixed(req, issue_flags); @@ -256,6 +256,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) goto err; } + ret = -EBADF; spin_lock(&files->file_lock); fdt = files_fdtable(files); if (close->fd >= fdt->max_fds) {