Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755243AbbGPKXb (ORCPT ); Thu, 16 Jul 2015 06:23:31 -0400 Received: from foss.arm.com ([217.140.101.70]:43100 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754660AbbGPKX3 (ORCPT ); Thu, 16 Jul 2015 06:23:29 -0400 Date: Thu, 16 Jul 2015 11:23:26 +0100 From: Will Deacon To: Joerg Roedel Cc: "grant.likely@linaro.org" , Rob Herring , "linux-arm-kernel@lists.infradead.org" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , "devicetree@vger.kernel.org" , Joerg Roedel Subject: Re: [PATCH 1/2] of: base: Allow more args than MAX_PHANDLE_ARGS if required Message-ID: <20150716102325.GC26390@arm.com> References: <1437035444-13867-1-git-send-email-joro@8bytes.org> <1437035444-13867-2-git-send-email-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1437035444-13867-2-git-send-email-joro@8bytes.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2200 Lines: 57 On Thu, Jul 16, 2015 at 09:30:43AM +0100, Joerg Roedel wrote: > From: Joerg Roedel > > The main use of MAX_PHANDLE_ARGS is to define the number of > args elements in 'struct of_phandle_args'. This struct is > often declared on the stack and thus it is impractical to > increase MAX_PHANDLE_ARGS again and again. > > To handle situations where more than MAX_PHANDLE_ARGS > elements may appear in a device-tree, introduce functions > to allocate/free 'struct of_phandle_args' with more than > MAX_PHANDLE_ARGS elements and provide the new function > of_parse_phandle_with_var_args(), which can handle those > variable-size structs. > > This is necessary for the ARM-SMMU driver, where the number > of mmu-masters can be up to 128. > > Signed-off-by: Joerg Roedel > --- > drivers/of/base.c | 43 ++++++++++++++++++++++++++++++++++++------- > include/linux/of.h | 7 +++++++ > 2 files changed, 43 insertions(+), 7 deletions(-) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index 8b5a187..2b288db 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -54,6 +54,24 @@ DEFINE_MUTEX(of_mutex); > */ > DEFINE_RAW_SPINLOCK(devtree_lock); > > +struct of_phandle_args *of_alloc_phandle_args(int size) > +{ > + struct of_phandle_args *args; > + int e = max(0, size - MAX_PHANDLE_ARGS); > + > + args = kzalloc(sizeof(struct of_phandle_args) + e * sizeof(uint32_t), > + GFP_KERNEL); Should you also update args->args_count to reflect the extended array? That said, extending the fixed-size array member like this feels a bit fragile. Does GCC not complain about out-of-bounds accesses if you statically address args->args[MAX_PHANDLE_ARGS]? Admittedly, I can't think *why* this would be break (things like additional padding will be harmless), but I'm not intimate with the C standard. I guess the more worrying possibility is if somebody adds a new member to the end of of_phandle_args. Will -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/