Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6507109rwi; Mon, 24 Oct 2022 02:18:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4SDDs4z4crvzUPaIy4SDsDL34rukZlMRcywONk7o7IheTRrm6/dwuyJpRYAA7Wyi/+H75H X-Received: by 2002:a17:90b:4c02:b0:20a:7d26:149 with SMTP id na2-20020a17090b4c0200b0020a7d260149mr75023097pjb.134.1666603081796; Mon, 24 Oct 2022 02:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666603081; cv=none; d=google.com; s=arc-20160816; b=g7dtBLx9yhBJeuE4vf/V4p5VSrNFSQfuBs68+CpgTdq9HvyzTuq630zYccUt/3juzn cfpCkh6rs9QTONMTF2q8bg9epGkG9RzzRNuv0AMAetwtR9HgPpJIGnEmhsT3cAzjHIio tagxgndlzob26rRcn4hmIIYdID4x7CJLxk/6t9wAj6dHJlGctli/sTGOtgsz3SXAj5dE iZf5UR7EKEF7I5pxClVXplt9yZ1iKmUDQp36GERMpD4V88IHzdTjipVJHAJWlJKKZhHC 2jgk3WD6hEZik3WGLGwl9lw6tRdM9AJrq1tdNALtz1KBrRCuoNvF6vigF65zkZkwoSCe jqYg== 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=FViVU/MMdIV2wxcqgT2cghXJ0bqvYReW+bK7HnLBsyE=; b=D31vCAXw7FgbklBEup1gWuAcB8Hj8H18+yhKFFetj1RmO/SlRfpcPWcPu3Y/9ElcOY HRRl/xIQZN7H2RV5ivLIKxAWJY6LlqHDJnR4buvI9kaByShwt72oErgj+IeSIR6u1BzT GBRZRVhLYM7/jVKXgsLiXEDv7EUwV/B54cvhBmfg2ggHJbiI2kj+Lypzip3H4gjkDnfA CwIjx54vqNsnH3brsf/xrcj7TVFnHdyCPB5NWht5Wnl0BPv/YmKZqcYHm4YlsH8YJyPT keqNcDhLJ4vZ01nhvOMnybVbejLxi0T9gmhsa1UemEOHwl3kQ+Y6bTUsTvR2YtPazcgl QSnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dv+l4xum; 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 s1-20020a170902ea0100b0017f5dfeb82fsi35749870plg.204.2022.10.24.02.17.50; Mon, 24 Oct 2022 02:18:01 -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=@linuxfoundation.org header.s=korg header.b=Dv+l4xum; 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 S230193AbiJXIoA (ORCPT + 99 others); Mon, 24 Oct 2022 04:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbiJXIn4 (ORCPT ); Mon, 24 Oct 2022 04:43:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A82CA6053A for ; Mon, 24 Oct 2022 01:43:55 -0700 (PDT) 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 445A260C8F for ; Mon, 24 Oct 2022 08:43:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5556FC433D6; Mon, 24 Oct 2022 08:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666601034; bh=kkSKYh4hPUtKNT3gV0Aa752Z+gMIuW2gRmR1EBrqbzE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Dv+l4xumuD4BrMTg9XTO7HZxiyn8LaD2vnKktbwzR24MwEfl47MOuIHD3usK0eO+1 rBHHZ/Bvoy2toj3u5tLO9WNlnUgrM02BW8Fw73RcKo5GfgKWFWysefENn7dQ5+wAjy lB5jcQHmJJUZxlXBXYOYtVynHMjjAmUqfLvy6sXA= Date: Mon, 24 Oct 2022 10:43:52 +0200 From: Greg Kroah-Hartman To: Sakari Ailus Cc: linux-kernel@vger.kernel.org, Andy Shevchenko , "Rafael J. Wysocki" , David Laight Subject: Re: [PATCH 1/1] linux/container_of.h: Warn about loss of constness Message-ID: References: <20221024082610.74990-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221024082610.74990-1-sakari.ailus@linux.intel.com> X-Spam-Status: No, score=-7.6 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 Mon, Oct 24, 2022 at 11:26:10AM +0300, Sakari Ailus wrote: > container_of() casts the original type to another which leads to the loss > of the const qualifier if it is not specified in the caller-provided type. > This easily leads to container_of() returning a non-const pointer to a > const struct which the C compiler does not warn about. > > Signed-off-by: Sakari Ailus > --- > include/linux/container_of.h | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/include/linux/container_of.h b/include/linux/container_of.h > index 2f4944b791b81..c7c21d0f41a87 100644 > --- a/include/linux/container_of.h > +++ b/include/linux/container_of.h > @@ -13,6 +13,10 @@ > * @type: the type of the container struct this is embedded in. > * @member: the name of the member within the struct. > * > + * WARNING: as container_of() casts the given struct to another, also the No need for "also" here (sorry for the grammar nit.) > + * possible const qualifier of @ptr is lost unless it is also specified in > + * @type. This is not a problem if the containing object is not const. Use with > + * care. I do not think these last two sentences you added here are needed either. > */ > #define container_of(ptr, type, member) ({ \ > void *__mptr = (void *)(ptr); \ > @@ -27,6 +31,11 @@ > * @type: the type of the container struct this is embedded in. > * @member: the name of the member within the struct. > * > + * WARNING: as container_of() casts the given struct to another, also the > + * possible const qualifier of @ptr is lost unless it is also specified in > + * @type. This is not a problem if the containing object is not const. Use with > + * care. Same comments here. thanks, greg k-h