Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp557388rdb; Thu, 8 Feb 2024 13:57:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUiDAbLVb8DK0CWAil0SNmjraRxrjvZnSVIPfItvVOx37LFBURpSFHUeWcS+r5JlWEyD6P9iCQ9OsOxSjdGEmMEsMEmEzijbToOc95l2Q== X-Google-Smtp-Source: AGHT+IGkAb8EVkKws3+OfgE2vu8Ej7PH7hAz56WXT+FTy/iTvl+wAbnNMyir7a560RNqLamI2fKt X-Received: by 2002:a9d:5e13:0:b0:6e2:b26f:82d4 with SMTP id d19-20020a9d5e13000000b006e2b26f82d4mr980227oti.23.1707429439927; Thu, 08 Feb 2024 13:57:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707429439; cv=pass; d=google.com; s=arc-20160816; b=CaclBw0MDjGEBBJZKYmKiFfgfxTB4Hc3rV8HehJxTaD2woBRP+AZEtfOTaDQgLqwZT iil6KhiE0uieRtYdlGN3KduTHU3hKPe9QHrXrSRLRcKlyyYWThyIM4MfzgFqZCL5WX0D tvJZ2pN88YKc6/p2YLr05qJk+GSMZX8hD0QSjXJiiHkjL2+r6RD/Kx0zmSGhJNmc/z+K +zOUZShfDtq8Xgnf24iS4v3xq/XPfqe8HX7eY2TlQyKgYvueJjj+nKZwdTJKb+4m8k83 M9Xow/lqcWRGnvktUOZP/j+LDhdCE9zuZCA2Xg0JNsR3dIbgGklemQhy8Ys2QzlUm4rP 2udg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=uuBkW91bKSdtv/qP/AAZDiygwHtnsXoTG5ybHQAGsCM=; fh=AjKdehBxJcV9pMXyWpMPSZ7t6gQu8vCEYcyF0FwTnu0=; b=XHQMIGpFD/OPdALWr+xQ8Os0XDFdnySF9KP3u4796azusJLjW0/YAbe3Yn2GZxQKu1 3YGXrvcZsmneQTSSLim9QGYP4V5/cInO7VvFvJ7Bhaj6CfQtaIFBZoZyYifVfXCCkARG gFpLgNBMlNQNxo210kkdtAONKOyPeKU5CTM33soOkesFWqGrTbcl3nXFvj0JNr7U9Ajh /LatfvsIlODJHARpNL3vKvSNAg4l1WQlF5BPcAA9+9Hv+rPx3uhnv+MErYxfVxKc122T dRztP21Pa73e0BVwRXySFI4ShIB7Y+sx+lUrpiRawbqBaZRfSCfUM7bd3RUW50cddaFe 64KA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ciA597Dv; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-58745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCXFHY1Aon1YJDxsqi12ZXyt+aA8o7Nzd81TYFtw5dPLeLTrXx3dcfohWcLpfQJ6RUpRZS5ZlA1f8+k9ul1M1NQVmICN5DW+dkIAKNfN5w== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u25-20020a05622a199900b0042c3986d756si410561qtc.129.2024.02.08.13.57.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 13:57:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ciA597Dv; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-58745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 A222F1C21E4A for ; Thu, 8 Feb 2024 21:57:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2D6B4F5ED; Thu, 8 Feb 2024 21:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ciA597Dv" Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 A05F04F5E9 for ; Thu, 8 Feb 2024 21:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707429430; cv=none; b=KP2+xn/LBVDjU2MuAwdG/XzbXp02jEmt/PNciNXZ7IRtYIHTwwL35DKBdeGl1+2xzm7gBbugWS2eehj9ihjAiFEOT9lghH5gVd9sp7QS1saZa+ec6a8DC6RYyCrpgjKbl05ypcEfH/XubYYb2ZwOZ6/8FUhdo7N98t16QiXQWbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707429430; c=relaxed/simple; bh=526f+OIfR5lt7kk3+KKqpP0mRWkrmTnf4eSgFYgV+j8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uG08TFTDQs7/I2M52umtXOPqNT9zmVPUJb/9w7yxuvfyiXnMTRYnT/umW+VGnDAYt6dddtFrTsVD9zK43plkgr19la/lkCfNxqOQnnz9IKxVtNIE79r5Bw9/y4S3WrYKboCQh5T2k0emnQDZPm4E4hCd7SV/aqwEdsdfL2nRlcI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ciA597Dv; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Thu, 8 Feb 2024 16:57:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707429426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uuBkW91bKSdtv/qP/AAZDiygwHtnsXoTG5ybHQAGsCM=; b=ciA597DvX/DbqrTOLewrCkHfHBc/438L8b8bIJN6CwD5wXKHgud0/jNmgQd8T0Vhq5sRMM DY9x3M/y9L9tfX6w9wgoyPrzZZVj1tYtot8PgdAvz9gONZyuRvVtX0FcVjBeVBtSxccL1v 5x4xoLO0gU3MmkLq/DnwI/tXqKf2PFg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Brian Foster Cc: Dave Chinner , brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner , "Darrick J. Wong" , Theodore Ts'o Subject: Re: [PATCH v2 3/7] fs: FS_IOC_GETUUID Message-ID: References: <20240206201858.952303-1-kent.overstreet@linux.dev> <20240206201858.952303-4-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Wed, Feb 07, 2024 at 08:05:29AM -0500, Brian Foster wrote: > On Tue, Feb 06, 2024 at 05:37:22PM -0500, Kent Overstreet wrote: > > On Wed, Feb 07, 2024 at 09:01:05AM +1100, Dave Chinner wrote: > > > On Tue, Feb 06, 2024 at 03:18:51PM -0500, Kent Overstreet wrote: > > > > +static int ioctl_getfsuuid(struct file *file, void __user *argp) > > > > +{ > > > > + struct super_block *sb = file_inode(file)->i_sb; > > > > + > > > > + if (!sb->s_uuid_len) > > > > + return -ENOIOCTLCMD; > > > > + > > > > + struct fsuuid2 u = { .len = sb->s_uuid_len, }; > > > > + memcpy(&u.uuid[0], &sb->s_uuid, sb->s_uuid_len); > > > > + > > > > + return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0; > > > > +} > > > > > > Can we please keep the declarations separate from the code? I always > > > find this sort of implicit scoping of variables both difficult to > > > read (especially in larger functions) and a landmine waiting to be > > > tripped over. This could easily just be: > > > > > > static int ioctl_getfsuuid(struct file *file, void __user *argp) > > > { > > > struct super_block *sb = file_inode(file)->i_sb; > > > struct fsuuid2 u = { .len = sb->s_uuid_len, }; > > > > > > .... > > > > > > and then it's consistent with all the rest of the code... > > > > The way I'm doing it here is actually what I'm transitioning my own code > > to - the big reason being that always declaring variables at the tops of > > functions leads to separating declaration and initialization, and worse > > it leads people to declaring a variable once and reusing it for multiple > > things (I've seen that be a source of real bugs too many times). > > > > I still think this is of questionable value. I know I've mentioned > similar concerns to Dave's here on the bcachefs list, but still have not > really seen any discussion other than a bit of back and forth on the > handful of generally accepted (in the kernel) uses of this sort of thing > for limiting scope in loops/branches and such. > > I was skimming through some more recent bcachefs patches the other day > (the journal write pipelining stuff) where I came across one or two > medium length functions where this had proliferated, and I found it kind > of annoying TBH. It starts to almost look like there are casts all over > the place and it's a bit more tedious to filter out logic from the > additional/gratuitous syntax, IMO. > > That's still just my .02, but there was also previous mention of > starting/having discussion on this sort of style change. Is that still > the plan? If so, before or after proliferating it throughout the > bcachefs code? ;) I am curious if there are other folks in kernel land > who think this makes enough sense that they'd plan to adopt it. Hm? That was the discussion :) bcachefs is my codebase, so yes, I intend to do it there. I really think this is an instance where you and Dave are used to the way C has historically forced us to do things; our brains get wired to read code a certain way and changes are jarring. But take a step back; if we were used to writing code the way I'm doing it, and you were arguing for putting declarations at the tops of functions, what would the arguments be? I would say you're just breaking up the flow of ideas for no reason; a chain of related statements now includes a declaration that isn't with the actual logic. And bugs due to variable reuse, missed initialization - there's real reasons not to do it that way.