Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1946286rwb; Fri, 2 Dec 2022 03:27:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf75tjaJTfTEMtkIr8AOKwhfl4D3CZTKYGOrnlQrfr5S88CfMQnvxQAncq8klThUSwQE26i3 X-Received: by 2002:a62:ea18:0:b0:56c:2d:1e56 with SMTP id t24-20020a62ea18000000b0056c002d1e56mr52691670pfh.41.1669980479419; Fri, 02 Dec 2022 03:27:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669980479; cv=none; d=google.com; s=arc-20160816; b=qforldJfFPCb/Q+xSFj2kyVEFel8Y5wxLbG3TL4tPIXsFpugp/O5Y8ugtZHT3cZOjx XbkmqdC+9FYY+snK+28o7NDbB9TnMHGYhdVhoSfXsi+D1otnxL9zGVlIpBYhEj0ZP68A wEHlycO1qG7fgpn0rqMphKL4Ijecsde96xiGMlG9+dN7z+qGIb4FOobLttgU4nubLJjI aFn3Hk7NkuSIQjhhR3fajuhXYz7M4VzYEa0z2ZhZzIt/1VCou3Bag/OXZHItdTKYNYlV EnP1Cv/cv97WIetAQAkr2ExSwhPeMypLfOWg16J9ZEMvjWPl7e/DIKh141A2tAa1Rst8 r74A== 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=Y1AH+mMJfyf71YCNtCw1rEw9izUYE3M3V3eMob83yp8=; b=X1iUKCR95ZrrwJ0or+dfPE78Q/f08wXfBhJ8XvCshhxpatq68nbIAhQAWByV/ctV15 rs2S4D+cmYn6MlXhUwYo7eRNKRYPaSt4X3CRZbbQeAV0TMlxCZGPhcZw9hHLndA1ainz fhjSeKSniflDy4b8TNJwSEV9ebNxxiiS3BTqHD4+YfIvzHRMulOxepNscvTth7Zy6f1r zQf69FyVinq6B5N6ThL/DEkaLZVI5rxgmXjIs0hb/Lr/vWj6Q0n/Q8Aqv6KD8BHCE2hB Aq4mE99m7797x42mRUzBlldYcTUbZ/rORvcg90liKoR7MLXdn90AbzJI680uqR86+uqR 4K8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WShGELSc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc1-20020a17090b3b8100b002187965af4csi8554367pjb.71.2022.12.02.03.27.43; Fri, 02 Dec 2022 03:27:59 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=WShGELSc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232711AbiLBKqH (ORCPT + 83 others); Fri, 2 Dec 2022 05:46:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231637AbiLBKqF (ORCPT ); Fri, 2 Dec 2022 05:46:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D14612316F for ; Fri, 2 Dec 2022 02:46:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 702B76224F for ; Fri, 2 Dec 2022 10:46:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14BEAC433C1; Fri, 2 Dec 2022 10:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669977960; bh=oYNvYKgo9dv4+IjQsFMYDOltTsZ4YmJhVPualRc6LWw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WShGELScDTzyHeMKcnDRonBe/P+M8j5R9aQqFBKWQVS6t1/We3daFe1pLIwMOe/MV 9hidiD3UJpRZfFLEWqlKxS2hs8ORGxsA2LcvnMjuvCcmc8ACFlIL/8XdIM4foLNAQe +or2DEeWWkrda+581dU2nZEJbnNtES9h/ta9nX9Y= Date: Fri, 2 Dec 2022 11:45:55 +0100 From: Greg Kroah-Hartman To: Sakari Ailus Cc: linux-kernel@vger.kernel.org, Jason Gunthorpe , Matthew Wilcox , Andy Shevchenko , "Rafael J. Wysocki" Subject: Re: [PATCH 1/4] container_of: add container_of_const() that preserves const-ness of the pointer Message-ID: References: <20221201193057.1195255-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Thu, Dec 01, 2022 at 11:21:50PM +0000, Sakari Ailus wrote: > Hi Greg, > > On Thu, Dec 01, 2022 at 08:30:54PM +0100, Greg Kroah-Hartman wrote: > > container_of does not preserve the const-ness of a pointer that is > > passed into it, which can cause C code that passes in a const pointer to > > get a pointer back that is not const and then scribble all over the data > > in it. To prevent this, container_of_const() will preserve the const > > status of the pointer passed into it using the newly available _Generic() > > method. > > "_const" in the name suggests that the macro would always take a const > argument. I mean it here to be "this will preserve const" as yes, it can take a const. Or not. > Could this be called e.g. container_of_safe() (for type-safe, but > full type_safe would be a bit long)? const is an attribute of type safety, container_of is also type-safe as-is, it's just the const portion here that is the difference between the two. Naming is hard :( > > -- > Kind regards, > > Sakari Ailus