Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6490211rwi; Mon, 24 Oct 2022 02:03:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fX6PyXjC3/Y9ODlvaWGZAqSXkWCQQDsd91CwGFnlHjYBgo59R1V/tSzaE3UhX/zJGWGgZ X-Received: by 2002:a17:907:a05:b0:77b:b538:6476 with SMTP id bb5-20020a1709070a0500b0077bb5386476mr27043461ejc.324.1666602221332; Mon, 24 Oct 2022 02:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666602221; cv=none; d=google.com; s=arc-20160816; b=SMkr77bAtC2vZ6J1n01RIwUyxaifPBteHn4W0FPaqJ24W41SHpbaWSPxebDAMbnFQt fD/rDibDUamw/VoWTqIIogtATIBjz2iU5dZJW2j9XIp/Wu6RMVLOnAlhIfPz/sI15mSi Fhjj+wfZ5Fanbcr95KjTmvFSO4tDi9cHWWfkrpYVYB77ONPTBJgRBbRmA0wmBEaan7dq OSSIqZbnWVKaKDj4d3BKTF/pqG1sPCxlUMIzlGrHh254FONHKP0tDsvmi+H0rrJ+Hyl8 ZNQL8WM399ao6w7jELSaST0XwlClw/KrYTuJLgKMhoaNoi861iMdFDEQ4g9g813vAd8X D88w== 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=E9CkaCLirwogfbcVjJcfSve9Nh98MQempT7nMiwKP7U=; b=n11AClVRwMmn5QQYgX1xAThUmB+KMN/OYLLa+krrx2dhB5W4XHQ9JvSzuDITuO1VtV lsyGS7WwBFI32RAfvo9mSMQMMM5am9CK1TFSJItedjXE0kd3010dRSCSw373827l61pj kZbTVEB6i9nn1pAx7I+eEZ5PaiyjOEH1RDuS2zUUbF3fLpVb6DFAtphBnL/CBpq/D2/0 lbwgTajIzyv5AB0CCzLMWF2SV9FMkeP3qLcfmNowLlaatLvgjSFqJvmNefLXFifcGwdr q7FbuqHC9VhuLtv+L+/16h6FQR/t+kZ2LvsFjii/59HTgsLJ4usdJDzuLCroLvjVcBwu Ijyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qUqqAC4b; 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 c26-20020a056402159a00b0046189831142si5196637edv.7.2022.10.24.02.03.16; Mon, 24 Oct 2022 02:03:41 -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=qUqqAC4b; 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 S230171AbiJXIph (ORCPT + 99 others); Mon, 24 Oct 2022 04:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbiJXIpe (ORCPT ); Mon, 24 Oct 2022 04:45:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F9E326DC for ; Mon, 24 Oct 2022 01:45:28 -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 4278A60DED for ; Mon, 24 Oct 2022 08:45:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F375C433C1; Mon, 24 Oct 2022 08:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666601127; bh=ZO+VTgM9VXFmY0M8fHk7daynC/+MUDqZPORFLMaf1p0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qUqqAC4bIyRX+W8dkbjaB7d8Ps2quaTmJ8ioBl5od+rzUAHxy+OBjrpkkiI6itvmC dTcEKG+ZxT5S5N/uE3XCu82khuCB37wqEJSP5j5c8hkaBfEUfUDE0TmMPu3MbwAs04 6m4332DqwYDTUs7wCeU3FfFaZf75Jo6qxZrRXUl4= Date: Mon, 24 Oct 2022 10:45:25 +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: 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 10:43:52AM +0200, Greg Kroah-Hartman wrote: > 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 Wrong function name here. > > + * 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. Wait, no one uses this macro, so why not just remove it entirely? thanks, greg k-h