Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp622501rwl; Thu, 23 Mar 2023 22:52:33 -0700 (PDT) X-Google-Smtp-Source: AKy350bTEuPdrwbY5JDWwrPY/KrEUrFRfdkxFRK7kF6R2aoWfLS+bzEP5Di8AQHnkCwV2TCJB2D3 X-Received: by 2002:a17:902:e0cd:b0:1a1:ae8d:1379 with SMTP id e13-20020a170902e0cd00b001a1ae8d1379mr1237441pla.7.1679637153504; Thu, 23 Mar 2023 22:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679637153; cv=none; d=google.com; s=arc-20160816; b=BNIqCwmAcA9CIfD5NXbOgwICB1QQsshKcsDNEH2J4g8xVuTtL/JT3a7g0QTR3sXyOf WWc1ohv5dhWMI5xkDbiBuOFeol9G9WcFvYS+cpjOgDCXBNIxaQckvcn8tAzjtSRAT86b A0+gLdAcze0OYlDcgUJx5gIJfPaTcOCyYjorDxwjLV9JlaWoTkZqwyRSf4kpjm3SU0iD 6wj/sM5zeOlTn5ffrnx9PKm9d3YQvia/IPbxrqCVN7h5+9mw1EmYaHi8YBPAgbzS2pXK ONdKHb6FUD6jrDQ6TblffBA5Jon3Jn3zrfWX4Sp9ZBuZjQlSXY3qykGi7RhW0VrNDnrJ GDog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TV7YjIHRnPh40nGPyD/b78oZpFAOJePPPC7MTmz9a1E=; b=EmYm38XuBsmy31xp4R00jz5Sj2RPtq3zoQI6alr5OfQYVD6y20tO3nEV+pKXFmQl5p vRxj7X0qwT7CgzfQgfsA7QtERNmYHvvCw6EE6ecQZD4PdsfI9PtSCAuQuMIoltKktdqq Tb9ghKpxMaeqc1phl75l4vZd5So8VmqXYv2/tIh9BkGZBigtJAo0LPI1juxwYVYRB+iJ kyOMgTDl+9efK1yOXfW0DCgTqUL3y84nTB8fIhDmXDR1k1X59jOI4FTrVApl4ZH3ovxt ZGiKNfZAlQ1lizJ5h+pssg9dJQp28/Cy0goXiKhnTiazkp6Jz4Sp3M2Z4/jl9cOBxU8G ysXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EIrDU50r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj11-20020a056a02018b00b005130ed530ffsi3770928pgb.529.2023.03.23.22.52.20; Thu, 23 Mar 2023 22:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EIrDU50r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjCXF3q (ORCPT + 99 others); Fri, 24 Mar 2023 01:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231531AbjCXF31 (ORCPT ); Fri, 24 Mar 2023 01:29:27 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA4987EC6; Thu, 23 Mar 2023 22:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=TV7YjIHRnPh40nGPyD/b78oZpFAOJePPPC7MTmz9a1E=; b=EIrDU50rOI3Xz29qFSRpu11dlA AedAprTuENA3LXMn+itdT5GR8eAmD+eYCT3X4rZmtp4UwlAAU8ysqXbRrEEaoALSZXOL/lv92RfZ5 oedESncsWBOyYdJkBfy9QKdZFQ0kXzMJFlweZE5RgLd+7F+FbeJQX27xvC1kLDBcgOc4gFKjVIW4M 9v8nh1N7zFi8SoHMrM1ErH84s8Y/jRKPjVoRo6c/0po/nnr2fqcyF5TCBjFPXdljmDUAmAPIxXO54 fanlmz0MKjaVGp95DOScKK1RaL1ogjU/bQShSDQM9950rIzQb8+J5fGUhABDotI4f4zS7lBqqGPE0 nBANTGKA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pfZyA-004bql-1q; Fri, 24 Mar 2023 05:28:06 +0000 Date: Fri, 24 Mar 2023 05:28:06 +0000 From: Matthew Wilcox To: aloktiagi Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, David.Laight@aculab.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, keescook@chromium.org, hch@infradead.org, Tycho Andersen Subject: Re: [RFC v3 2/3] file: allow callers to free the old file descriptor after dup2 Message-ID: References: <20230324051526.963702-1-aloktiagi@gmail.com> <20230324051526.963702-2-aloktiagi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230324051526.963702-2-aloktiagi@gmail.com> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 24, 2023 at 05:15:25AM +0000, aloktiagi wrote: > @@ -1119,8 +1119,12 @@ __releases(&files->file_lock) > __clear_close_on_exec(fd, fdt); > spin_unlock(&files->file_lock); > > - if (tofree) > - filp_close(tofree, files); > + if (fdfile) { > + *fdfile = tofree; > + } else { > + if (tofree) > + filp_close(tofree, files); > + } Why not: if (fdfile) *fdfile = tofree; else if (tofree) filp_close(tofree, files); Shorter and makes the parallel structure more obvious.