Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1185702 > unrolled thread

Re: [PATCH 1/2] of: base: Allow more args than MAX_PHANDLE_ARGS if required

Started byWill Deacon <will.deacon@arm.com>
First post2015-07-16 12:30 +0200
Last post2015-07-16 13:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 1/2] of: base: Allow more args than MAX_PHANDLE_ARGS if  required Will Deacon <will.deacon@arm.com> - 2015-07-16 12:30 +0200
    Re: [PATCH 1/2] of: base: Allow more args than MAX_PHANDLE_ARGS if  required Joerg Roedel <jroedel@suse.de> - 2015-07-16 13:10 +0200

#1185702 — Re: [PATCH 1/2] of: base: Allow more args than MAX_PHANDLE_ARGS if required

FromWill Deacon <will.deacon@arm.com>
Date2015-07-16 12:30 +0200
SubjectRe: [PATCH 1/2] of: base: Allow more args than MAX_PHANDLE_ARGS if required
Message-ID<pMOAp-3Pj-5@gated-at.bofh.it>
On Thu, Jul 16, 2015 at 09:30:43AM +0100, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> 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 <jroedel@suse.de>
> ---
>  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/

[toc] | [next] | [standalone]


#1185724

FromJoerg Roedel <jroedel@suse.de>
Date2015-07-16 13:10 +0200
Message-ID<pMPd8-4Ps-17@gated-at.bofh.it>
In reply to#1185702
Hi Will,

On Thu, Jul 16, 2015 at 11:23:26AM +0100, Will Deacon wrote:
> On Thu, Jul 16, 2015 at 09:30:43AM +0100, Joerg Roedel wrote:
> > +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?

The args_count member just tells us how many of the array elements are
used and not how many there are. So it doesn't need to be updated here.

> 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.

Yeah, I agree, it is not the best possible solution. But this way I
don't need to update all callers, and thus it works better with our
development model.

But I am open for suggestions on how to solve this problem better. In
fact, my main motivation in sending this was to get the discussion about
an upstreamable solution started :)

Lets see what the device-tree maintainers have to say.

> I guess the more worrying possibility is if somebody adds a new member to
> the end of of_phandle_args.

I should probably add a comment there.



	Joerg

--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web