Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2524941imm; Thu, 7 Jun 2018 12:07:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLOGGBptuWtNlezzw6R4zAv6z+u7F+GzFZ1P1mTBsrbCbVrG2STRhgzpo2ytuWlopjIxvmM X-Received: by 2002:a17:902:7446:: with SMTP id e6-v6mr3227209plt.382.1528398420056; Thu, 07 Jun 2018 12:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528398420; cv=none; d=google.com; s=arc-20160816; b=tEW7yXtKHoJB1KLYuJy95DXPENnrx3VQqqmbMbs2wWVqCsTqjTNwnq/AGFpFXYxi9u QZV/5dP82y7S+fsPu+RcTMnTGx8+YfPoy1Qre8ChQ6nwBKDalY1Ny+F/Jt/gW2zc72SF y+6uZ0+38piDrrf2ceCjbNciT9Y5QxfOrpAzqS5frrW4rsX+Ci0E4dQGR7MWgUhoj9mL BNUyLKD3Gm8SKhuUHXgagciaZ9ghv4hY6tX4imM59SjiLQ7DYfXyZWmF7KRBT4ubF/nZ DoVCNfCXQL5eQUvH6wnjuHq6BcXWBJW6rl+iYYsYUpCylLrPrDUJ5KSMhLPFa7zyT/CY xnWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=7/mHzYQRX+SJHkYjy4GOadz/8D9Xeaz9d1ya3B+jmpo=; b=Gv/yhhxdj+qEUqzLoqziLh61Zn1uzJbNdEifwNR6oXi8lHRVSSm7O4EM4IKTPftK9S aj3PKs5Jl93m6TsHaeFmtyh1uaDWQgHXhKSMciE5iu0hyU9aqCi36pfHM/iveuV84fjl a3el9ZkYtwCj8/+1oeCRYETFcA/4kvf5UGtqY0Xb3krBKPoNm5d7hRZn0y/9xKDC2b5K rWIdPd9I/Zi2alMHVzwnL5zO9XlVJ8/Ki0StFBL3IML5IqeQ8b1vB6cnYTVLhZZenPsB TrT+pytOjiZ+1zLSNy/KlMWTn2fRiLOsiQT33cP6s9UEG5CD26e3ABOPUD0AF3Jd4lmf Yorw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7-v6si14950929pgr.76.2018.06.07.12.06.45; Thu, 07 Jun 2018 12:07:00 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933790AbeFGR3w (ORCPT + 99 others); Thu, 7 Jun 2018 13:29:52 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:6989 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932648AbeFGR3v (ORCPT ); Thu, 7 Jun 2018 13:29:51 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1, AES128-SHA) id ; Thu, 07 Jun 2018 10:30:01 -0700 Received: from HQMAIL105.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 07 Jun 2018 10:29:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 07 Jun 2018 10:29:50 -0700 Received: from rcampbell-dev.nvidia.com (10.110.48.66) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 7 Jun 2018 17:29:50 +0000 Subject: Re: [PATCH 6/6] Convert intel uncore to struct_size To: Matthew Wilcox , Kees Cook CC: Matthew Wilcox , , , References: <20180607145720.22590-1-willy@infradead.org> <20180607145720.22590-7-willy@infradead.org> From: Ralph Campbell Message-ID: <03d9addb-9c68-c6e5-d7db-57468fc3950c@nvidia.com> Date: Thu, 7 Jun 2018 10:29:49 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180607145720.22590-7-willy@infradead.org> X-Originating-IP: [10.110.48.66] X-ClientProxiedBy: HQMAIL104.nvidia.com (172.18.146.11) To HQMAIL105.nvidia.com (172.20.187.12) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/07/2018 07:57 AM, Matthew Wilcox wrote: > From: Matthew Wilcox > > Need to do a bit of rearranging to make this work. > > Signed-off-by: Matthew Wilcox > --- > arch/x86/events/intel/uncore.c | 19 ++++++++++--------- > 1 file changed, 10 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c > index 15b07379e72d..e15cfad4f89b 100644 > --- a/arch/x86/events/intel/uncore.c > +++ b/arch/x86/events/intel/uncore.c > @@ -865,8 +865,6 @@ static void uncore_types_exit(struct intel_uncore_type **types) > static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) > { > struct intel_uncore_pmu *pmus; > - struct attribute_group *attr_group; > - struct attribute **attrs; > size_t size; > int i, j; > > @@ -891,21 +889,24 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) > 0, type->num_counters, 0, 0); > > if (type->event_descs) { > + struct { > + struct attribute_group group; > + struct attribute *attrs[]; > + } *attr_group; > for (i = 0; type->event_descs[i].attr.attr.name; i++); What does this for loop do? Looks like nothing given the semicolon at the end. > - attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) + > - sizeof(*attr_group), GFP_KERNEL); > + attr_group = kzalloc(struct_size(attr_group, attrs, i + 1), > + GFP_KERNEL); > if (!attr_group) > goto err; > > - attrs = (struct attribute **)(attr_group + 1); > - attr_group->name = "events"; > - attr_group->attrs = attrs; > + attr_group->group.name = "events"; > + attr_group->group.attrs = attr_group->attrs; > > for (j = 0; j < i; j++) > - attrs[j] = &type->event_descs[j].attr.attr; > + attr_group->attrs[j] = &type->event_descs[j].attr.attr; > > - type->events_group = attr_group; > + type->events_group = &attr_group->group; > } > > type->pmu_group = &uncore_pmu_attr_group; >