From patchwork Mon Oct 24 08:26:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 8231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp319871wru; Mon, 24 Oct 2022 01:28:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6U8BmshlU8zBd38fIS/iL3YIPqmr6XkBK4EBp167XyLWOusfvFJiQlywkPUGTuD9WfR17B X-Received: by 2002:a17:907:7fac:b0:7a1:cace:1352 with SMTP id qk44-20020a1709077fac00b007a1cace1352mr8147666ejc.6.1666600095941; Mon, 24 Oct 2022 01:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666600095; cv=none; d=google.com; s=arc-20160816; b=OQeJ2rZXnzM7pOZUpgPfrcUiP6K3MUK8mXVfvvItaNdKONrAkTXfkrM+/3izXu1e7X yj0jVqo3ocW2A7KBV+esFaxtd/riyLMyvYUgL7jjnlyf5dK208k5yM1Zd53EZUGKOJVx BwOsrpET4JzfT/X1NTqMz/C5JepymoAwSpwEgzq5JcG1kgBCE1mOS57/f3dU2FUCJydV 7Ldzb/0BJPRD1/ljTbgiRVKpUmLgRsWId9sMnBn3KGQjyn/P4nGYEoYYM58374z7Vyx8 LsoTfJIkf1RhMDBLD0PQAajmfoN5QT/5YcN4lIhNhH9U0jWMUHYHXcnzTb03JCKnUENN Go9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=eU9w4x9+g5pzprFKAl9bdoNxMinEpFEA1EC7f9NncTA=; b=0LOTfs6zPCFa27sX070to1r5fT7Lv4Zdc0bpEvMo0RPzv46b8ukGvydSkAkTritQt7 GX3Dh4yEASM5j2fzHwB1RPbZKfMHXe5iHMbJoVedh9wSe4YS2oLtjpGxL3yjgq6a3uOH pHmmsBbZyCaLPcinxf8uNqhERZNoGTPWhVrdeXWIvHYUjcCShjp7VP16fIqJMOTKhl8l tIHZvbrjdI8erbEon2Z5wdoKZ1RPts/AzXFgAAaMqiwC06wvUa1s9DQucfknt96k6TAw RCNI+QswEPzEqtG3jNk3MHic7uLZcpBF6EwieSjR1Jhg9AXTU1JFFLpotkmHV0qmveWM UkCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TPxEq8mp; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk36-20020a1709077fa400b007919fc02ce8si16286717ejc.971.2022.10.24.01.27.52; Mon, 24 Oct 2022 01:28:15 -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=@intel.com header.s=Intel header.b=TPxEq8mp; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230311AbiJXI1C (ORCPT + 99 others); Mon, 24 Oct 2022 04:27:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbiJXI0f (ORCPT ); Mon, 24 Oct 2022 04:26:35 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 926EEFAC0 for ; Mon, 24 Oct 2022 01:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666599949; x=1698135949; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YJtA74YQm4A6lPUrh3QtcR1iB0PmZLMp2ejYydWO/IA=; b=TPxEq8mp05Wb68t27HgUmeOCQZNhx6N/jagSq59RlJlCDSeZq2LlhUpS jREuRvgNG8y+B/HojpGvdSfTcMF9+XiXO5JjW4pcp1me4CxPjGkuLOwyC KUYyFUo5bRsrI8p5I5ZSwMEiii2PWlGMmn3vfAe4FrgftULICtv1y7Fcw LwYLiPzjI634Ob2YRjZnfHtOFzuQrois70Oa/oJE+LBuUQVkkI6upMhnx xy749sNt/IWW7VgRWgloRLQA20WwIX/63KyzHtSHxepacFcdfp/mCGrFJ 4a5/cEFke2ssANc88AqwjslPToVie6reB1ZvE2lHSt4xH4BOORVI/0fdr g==; X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="307356793" X-IronPort-AV: E=Sophos;i="5.95,207,1661842800"; d="scan'208";a="307356793" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 01:25:48 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="806237388" X-IronPort-AV: E=Sophos;i="5.95,207,1661842800"; d="scan'208";a="806237388" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 01:25:44 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id D8F4D2021B; Mon, 24 Oct 2022 11:25:41 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1omsmg-000JWJ-PX; Mon, 24 Oct 2022 11:26:10 +0300 From: Sakari Ailus To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Andy Shevchenko , "Rafael J. Wysocki" , David Laight Subject: [PATCH 1/1] linux/container_of.h: Warn about loss of constness Date: Mon, 24 Oct 2022 11:26:10 +0300 Message-Id: <20221024082610.74990-1-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747556862081691433?= X-GMAIL-MSGID: =?utf-8?q?1747556862081691433?= 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 + * 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. */ #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. + * * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged. */ #define container_of_safe(ptr, type, member) ({ \