From patchwork Mon Apr 8 12:41:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 10889533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A26F41669 for ; Mon, 8 Apr 2019 12:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8391C28696 for ; Mon, 8 Apr 2019 12:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77C0F286B3; Mon, 8 Apr 2019 12:42:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7AC69286C1 for ; Mon, 8 Apr 2019 12:42:03 +0000 (UTC) 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-DC; 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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)