Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp718706ybi; Fri, 24 May 2019 10:17:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTYzT2dYU7BJXeJrMv3K7YPFmBBIkOJfJDiC2Ashn1crzVVbAy3cSERMigvMmP83W8kCZA X-Received: by 2002:a63:2ac9:: with SMTP id q192mr36279863pgq.144.1558718252371; Fri, 24 May 2019 10:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558718252; cv=none; d=google.com; s=arc-20160816; b=tAtIgSKPwSZwDKiCu+0dfMvBciUQDjl7cPhdan2A1ySKxgqvplHT3Mnj56TajwThvV gdZR0UlqIVM9noQt6J3cp/hVwh6rRNhX42047nBgse5h4QWTw6LqtFK4+KDPrVLVCdDz tuQL1kBiagmemUeccqz0w82Ch3ljAtpZsY5FyD0YP/IBWVs+nmfYy32i2+wKN16djDg1 7pXy/R7wUgzazkauDWNtXVH2GXY3kVr+IYa/SLcXM6h2hkaJwbHTsPJF13fxmh+/4grR Srmixo2e0jhMMATxMSFQsncLDiyjT2AwzkJm0PUW91q1qrio+kULLOIlaLa/UNm4IiHP mgOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=VWFzSUJtRiMM2O/iTROjpegpz6O+rySqKo1++Ws4pXU=; b=dbZpBCR4A+64Phm4JWYYIhQNXZq2pxHkOJEDT5FbkMWM/9TrGhiucYSqezt5CxAEbX FLoHNG5vS5cxqfAr/CXgIyFpw/GTAXyDB6Vud7q2KN79dDW6woSYrABnTOXpRHGKUxhX wOmMhODCaXvuP7Jbzjc2dgXfxisXIiIhwVhNr8eiESHm641V5jQ5MRlaqnDuZUrCWQh1 yGw25PbwLEjsgyCsJOpLzlCtB9oVZKeKkJ/JKsA+a0+TihAhM6N8T8pK8BVJW2WC8o5g HB+R9yI4pTzt3NbJKyuA6GOZZnQiMQZJMV4seK4QJ98QttZ0mJly0tvvY+QzPmB3YNms Kptg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13si4776241pga.385.2019.05.24.10.17.16; Fri, 24 May 2019 10:17:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731918AbfEXRPj (ORCPT + 99 others); Fri, 24 May 2019 13:15:39 -0400 Received: from gateway24.websitewelcome.com ([192.185.51.35]:11639 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725777AbfEXRPi (ORCPT ); Fri, 24 May 2019 13:15:38 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway24.websitewelcome.com (Postfix) with ESMTP id C4B6CEE8B for ; Fri, 24 May 2019 12:15:37 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id UDn7hZ2rl90onUDn7hd2MU; Fri, 24 May 2019 12:15:37 -0500 X-Authority-Reason: nr=8 Received: from [189.250.47.159] (port=51588 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hUDn6-002Ami-S9; Fri, 24 May 2019 12:15:36 -0500 Date: Fri, 24 May 2019 12:15:36 -0500 From: "Gustavo A. R. Silva" To: Ben Skeggs , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] drm/nouveau/mmu: use struct_size() helper Message-ID: <20190524171536.GA20883@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.47.159 X-Source-L: No X-Exim-ID: 1hUDn6-002Ami-S9 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.47.159]:51588 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 17 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used. So, replace the following form: sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr; with: struct_size(kind, data, mmu->kind_nr) This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- drivers/gpu/drm/nouveau/nvif/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nvif/mmu.c b/drivers/gpu/drm/nouveau/nvif/mmu.c index ae08a1ca8044..5641bda2046d 100644 --- a/drivers/gpu/drm/nouveau/nvif/mmu.c +++ b/drivers/gpu/drm/nouveau/nvif/mmu.c @@ -110,7 +110,7 @@ nvif_mmu_init(struct nvif_object *parent, s32 oclass, struct nvif_mmu *mmu) if (mmu->kind_nr) { struct nvif_mmu_kind_v0 *kind; - u32 argc = sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr; + size_t argc = struct_size(kind, data, mmu->kind_nr); if (ret = -ENOMEM, !(kind = kmalloc(argc, GFP_KERNEL))) goto done; -- 2.21.0