Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp995815pxa; Fri, 28 Aug 2020 00:11:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKHZZz96p2RF+LHkoyKLgpgiQeQxR0wtnu6nSDQJ3HjvsaW4/A87e8Zx7kzH6OTr0tm8DQ X-Received: by 2002:a50:ed8d:: with SMTP id h13mr459315edr.50.1598598692619; Fri, 28 Aug 2020 00:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598598692; cv=none; d=google.com; s=arc-20160816; b=hJRfe/KKVHBqWy/rScFSIUhjfnKYSh53w6zgqUBj3QZN/L0lgZYWI9LanOCrhgxvs0 uunAoHoOj3hluqsdxRsy6v7pt1AbMWqdolKr4koElpJvSaTbyJEC+nFlCqgEwJk6sBNH boDsexyI7XEkMS2susf3ifZN4w091zqDqvdNLg74OgK2R3Lx8YD7a7YBppbmHwaLgMlg Z0h5nBni10faVQ4umjArzC82KzhtXes9kEnDxYKI6lPVbVkzCPV8fiiO/hDazSE7GxQz 2I5nehA7yczf6Bsw79Q319ej8iciSqzAggNbcgQVFufBLQPUv0fOI2WPzh6iM8kdDCnT EPHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DVuVd6p5WUIda7pE1WrjTg4zSVXkLhlT+xCt0yR++Os=; b=A43hSu6A7WOtYGxOYo8xq+HX/qrjPcnCTtL7QGIo4Rgn1ZfBePAC8N+mB/Chcaj8Fz 7qNzZggmvWvGs8NksksZ840vYDi9G7l9r8W0IZNUPwIqIuHRfk29jjv9oc8RENZT93ei jl4MfddnjfWeKaIPFBNSN+jKXb0pm+snizgm2T7r4j94AHhMmvkkEsYcgcX2ZBRFbvBv BQ3CiWEspkEKRy4h4FhT79zHsSeRkSveuLvaP0jL2oLU35/JLVDMcV1RDxmG82Nr9IG2 4J6bIaoA6MJDozAmKprgFkxqfXknvX2kZW0+xg2TW/loJJdoyMaOGjfaZSnL5GqF2bUd h8VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aCtNnk7z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qk7si95984ejb.23.2020.08.28.00.11.10; Fri, 28 Aug 2020 00:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aCtNnk7z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgH1HJ6 (ORCPT + 99 others); Fri, 28 Aug 2020 03:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbgH1HJ5 (ORCPT ); Fri, 28 Aug 2020 03:09:57 -0400 Received: from mail-oo1-xc43.google.com (mail-oo1-xc43.google.com [IPv6:2607:f8b0:4864:20::c43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08FEBC061264 for ; Fri, 28 Aug 2020 00:09:56 -0700 (PDT) Received: by mail-oo1-xc43.google.com with SMTP id h4so49937oop.0 for ; Fri, 28 Aug 2020 00:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DVuVd6p5WUIda7pE1WrjTg4zSVXkLhlT+xCt0yR++Os=; b=aCtNnk7zEgx71MZ0li20Hed24dO1JYlQFvABddQov9B6BuQZwUGuM9rYoDcmcR52Rb PLiEcsslY2WP24AjQJw0BfdIs+Mi7yvPixtAe5JqSdWZv3MZHTAWBUnPiZJPdkNsdgZi TyQSEdNsqUa4842GX2ezZu2bFoau1JHYZnTi6c7jBCcctQz1uzXZ7aCz6j4JEEggblI1 9D4LNbT9BHiNPm7NVKLCf337hPFe0CzJWkwey3I3Rs2FE4ciiAXnRx/JmhEAeezsnNy3 dzVfgYQY8R7nCi/ooqV5pAoMs4ZYs7X1IUIkYr+yd6PUDPx/dnoZuyP9xuH3fmyXKqAl boxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DVuVd6p5WUIda7pE1WrjTg4zSVXkLhlT+xCt0yR++Os=; b=IHGP/DkPKLlOnp/5vAoTLko92cH8IC3lbWFThlO0pRjc7fFFX4lTV5EQmIrf24+bSj sTj389HrAsm9dI8Y4V4Ngq6o7bFSfDh+VmJTZUtoXhXxzemhUYzT8+J55sAMTZuC3uSg bL8iAbTB0JnandTxu+dc9Mlaz5rQ33/oa00lbph6cwZPGjLnNFXy6PMcSvzvtz3IM8eC 6VwmYQmyv5G+Hh+gDR4810DjHzFyy7zvP1HCnVh1ctHIAPCyOdbyIVTxz0KJJtrG7nFf FJ3KkkycX4i2v5Qqd3it+MMW83IeYKJlzFL/SusssmDUJVOsltnzMV4D52UKqWnjAio9 45pw== X-Gm-Message-State: AOAM5333mxWXwFuVrGuhghsLQIjaX20jM25xqxZ5olo1ILAlQ2ehMQCn 5ZCAHmiLq54LM8mUeYESKi0HpyvhSOeDly0LVZg= X-Received: by 2002:a4a:d588:: with SMTP id z8mr164471oos.84.1598598594507; Fri, 28 Aug 2020 00:09:54 -0700 (PDT) MIME-Version: 1.0 References: <20200827013636.149307-1-allen.lkml@gmail.com> <1598553133.4237.8.camel@HansenPartnership.com> <202008271150.7231B901@keescook> <20200827213636.GF1236603@ZenIV.linux.org.uk> <202008271503.181A6A609@keescook> In-Reply-To: <202008271503.181A6A609@keescook> From: Allen Date: Fri, 28 Aug 2020 12:39:42 +0530 Message-ID: Subject: Re: [PATCH] linux/kernel.h: add container_from() To: Kees Cook Cc: Al Viro , Linus Torvalds , James Bottomley , Andrew Morton , Thomas Gleixner , Linux Kernel Mailing List , Greg Kroah-Hartman , Jens Axboe Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > You really have to pick some pretty excessive type names (or variable > > > names) to get close to 80 characters. Again, to pick an example: > > > > > > struct timer_group_priv *priv = container_of(handle, > > > struct timer_group_priv, timer[handle->num]); > > > > > > ends up being long even if you were to split it, but that funky > > > container_from() wouldn't have helped the real problem - the fact that > > > the above is complex and nasty. > > The point about doing the assignment with the declaration certainly makes > the "ugliness" worse, I agree. I'm still not generally convinced about > the redundancy level pros/cons, but I concede that having a common idiom > (rather than a succinct but subsystem-dependent idiom) is better for > people reading the code for the first time. > > > > And I had to _search_ for that example. All the normal cases of > > > split-line container-of's were due to doing it with the declaration, > > > or beause the first argument ended up being an expression in itself > > > and the nested expressions made it more complex. > > > > Speaking of searching, this kind of typeof use is, IMO, actively > > harmful - it makes finding the places where we might get from > > e.g. linked list to containing objects much harder. container_of > > (unless combined with obfuscating use of typeof()) at least gives > > you a chance to grep - struct foo *not* followed by '*' is a pattern > > that doesn't give too many false positives. This one, OTOH, is > > essentially impossible to grep for. > > And this observation about workflow does strike a chord with me. I do end > up with those kind of searches too. In trying to examine my preferences > here, I think my instincts are to avoid open-coded types (leading me to > want to use typeof()) but I think those instincts were actually developed > from dealing with _sizeof_ and all the way it goes terribly wrong. So, > okay, I'm convinced. container_of() it is. so container_of() it is :) Will start updating the rest of the patches. Thanks, - Allen > Doing these conversions becomes a little less mechanical if assignment > needs to be split from declaration, but hey, we've got a 100 character > line "limit" now, so maybe it'll be less needed. :) > > -- > Kees Cook