OSDN Git Service

pinctrl: tb10x: Use flexible-array member and struct_size() helper
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Thu, 6 Jun 2019 23:11:44 +0000 (18:11 -0500)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 7 Jun 2019 23:29:43 +0000 (01:29 +0200)
commitd32aa74555575a0692f4e06fe39a673a1877eff6
tree60793254feef686146cff59bf83b1361db27d604
parent76c4c597b2ef59900933fca8893428f0555afaab
pinctrl: tb10x: Use flexible-array member and struct_size() helper

Update the code to use a flexible array member instead of a pointer in
structure tb10x_pinctrl and use the struct_size() helper:

struct tb10x_pinctrl {
        ...
struct tb10x_of_pinfunc pinfuncs[];
};

Also, make use of the struct_size() helper instead of an open-coded
version in order to avoid any potential type mistakes.

So, replace the following form:

sizeof(struct tb10x_pinctrl) + of_get_child_count(of_node) * sizeof(struct tb10x_of_pinfunc)

with:

struct_size(state, pinfuncs, of_get_child_count(of_node))

This code was detected with the help of Coccinelle.

Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/pinctrl-tb10x.c