From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DEF7C10F13 for ; Mon, 8 Apr 2019 12:42:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4EC62214C6 for ; Mon, 8 Apr 2019 12:42:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JU/Ckl4g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EC62214C6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=PcgDKMANo+9xKwdmtSZAcLwP1DBkdUiMiFPjNvWaIhg=; b=JU/Ckl4glpoeBY 03kwkYsDgr7GW4EMga7Ta63Uv6TxQoaE4oNUHU8xeWj6smHXkhjpMaf3WZ3DOvLTrSk52pnUSMk57 CB0vc1h0xLXKM7LaxC8XRZFLjqnuPZ+3gjve5VMS0no08iu4Xx8NumWvZM0NYvqlDrW7Hb9fI4R05 WOFuNPwJdjqROan99ApzJDgjD6oQkVY26dypSRaY0Zshsd1ubpU/WqxOk5eMdt9Es8HylaIpGys6X zzhfgEzvhqvv+C0MLiCDASBvXzGStXc3TJPBPjCF2Y5K4GalGZEpuZz4b9aPqjQGHDmudvZnvjGdX x+OBa7lCOdneIJFp/C/g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hDTb3-0002aq-Gz; Mon, 08 Apr 2019 12:41:57 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hDTb0-0002aW-O6 for linux-arm-kernel@lists.infradead.org; Mon, 08 Apr 2019 12:41:55 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0DCFD15BF; Mon, 8 Apr 2019 05:41:54 -0700 (PDT) Received: from e110467-lin.cambridge.arm.com (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 20CBA3F68F; Mon, 8 Apr 2019 05:41:52 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org Subject: [PATCH] iommu: Fix offsetof() usage Date: Mon, 8 Apr 2019 13:41:47 +0100 Message-Id: <85778a4619eab832eb0b003a68f377aea9d97b22.1554727307.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.21.0.dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_054154_791634_65EEBAAF X-CRM114-Status: GOOD ( 16.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: iommu@lists.linux-foundation.org, David Laight , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org David rightly points out that, although GCC lets us get away with it, using offsetof() with a non-constant member designator is not compliant with the C standard. I'm responsible for a couple of those misuses, but both in circumstances for which we now have a specific helper, so we can use that to put things straight. Suggested-by: David Laight Signed-off-by: Robin Murphy --- drivers/iommu/arm-smmu.c | 3 +-- drivers/iommu/iommu.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 74e944bd4a8d..81d449451494 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1484,8 +1484,7 @@ static int arm_smmu_add_device(struct device *dev) } ret = -ENOMEM; - cfg = kzalloc(offsetof(struct arm_smmu_master_cfg, smendx[i]), - GFP_KERNEL); + cfg = kzalloc(struct_size(cfg, smendx, i), GFP_KERNEL); if (!cfg) goto out_free; diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 33a982e33716..ad28919e1452 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2021,7 +2021,7 @@ int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) if (!fwspec) return -EINVAL; - size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]); + size = struct_size(fwspec, ids, fwspec->num_ids + num_ids); if (size > sizeof(*fwspec)) { fwspec = krealloc(fwspec, size, GFP_KERNEL); if (!fwspec) -- 2.21.0.dirty _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel