mfd: Fix MACRO for commonly declared MFD cell attributes
PATCH 1/1 mfd: Fix MACRO for commonly declared MFD cell attributes
MFD_ARRAY_SIZE() would not accurately return 0 if the passed parameter was NULL. Fix this so that num_resources will accurately be 0 in the case that _res is NULL.
--- include/linux/mfd/core.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
include/linux/mfd/core.h +9 -6
@@ -18,11 +18,11 @@#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) -#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ +#define MFD_CELL_ALL (_name, _nres, _res, _pdata, _id, _compat, _match) \ { \ .name = (_name), \ .resources = (_res), \ - .num_resources = MFD_ARRAY_SIZE((_res)), \ + .num_resources = (_nres), \ .platform_data = (_pdata), \ .pdata_size = MFD_ARRAY_SIZE((_pdata)), \ .of_compatible = (_compat), \
@@ -31,16 +31,19 @@ }#define OF_MFD_CELL (_name, _res, _pdata, _id, _compat) \ - MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, NULL) \ + MFD_CELL_ALL(_name, MFD_ARRAY_SIZE((_res)), _res, \ + _pdata, _id, _compat, NULL) \#define ACPI_MFD_CELL (_name, _res, _pdata, _id, _match) \ - MFD_CELL_ALL(_name, _res, _pdata, _id, NULL, _match) \ + MFD_CELL_ALL(_name, MFD_ARRAY_SIZE((_res)), _res, \ + _pdata, _id, NULL, _match) \#define MFD_CELL_BASIC (_name, _res, _pdata, _id) \ - MFD_CELL_ALL(_name, _res, _pdata, _id, NULL, NULL) \ + MFD_CELL_ALL(_name, MFD_ARRAY_SIZE((_res)), _res, \ + _pdata, _id, NULL, NULL) \#define MFD_CELL_NAME (_name) \ - MFD_CELL_ALL(_name, NULL, NULL, 0, NULL, NULL) \ + MFD_CELL_ALL(_name, 0, NULL, NULL, 0, NULL, NULL) \struct irq_domain ;struct property_set ;
Signature · 1 line
1.9.1
Quoted 30 lines · Rhyland Klein
MFD_ARRAY_SIZE()would not accurately return 0 if the passed parameter was NULL. Fix this so thatnum_resourceswill accurately be 0 in the case that_resis NULL.cc Lee Jones <[email protected]>cc Laxman Dewangan <[email protected]>Signed-off-by Rhyland Klein <[email protected]>--- include/linux/mfd/core.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)include/linux/mfd/core.h +2
-2@@ -18,11 +18,11 @@#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) -#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ +#define MFD_CELL_ALL (_name, _nres, _res, _pdata, _id, _compat, _match) \ { \ .name = (_name), \ .resources = (_res), \ - .num_resources = MFD_ARRAY_SIZE((_res)), \ + .num_resources = (_nres), \ .platform_data = (_pdata), \ .pdata_size = MFD_ARRAY_SIZE((_pdata)), \ .of_compatible = (_compat), \
include/linux/mfd/core.h line 35
Quoted 6 lines
include/linux/mfd/core.h +2
-1@@ -31,16 +31,19 @@ }#define OF_MFD_CELL (_name, _res, _pdata, _id, _compat) \ - MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, NULL) \ + MFD_CELL_ALL(_name, MFD_ARRAY_SIZE((_res)), _res, \ + _pdata, _id, _compat, NULL) \
I'm confused. Why would it be any different just by changing the call site of MFD_ARRAY_SIZE?
And what about .platform_data?
How about this change instead?
include/linux/mfd/core.h +1 -1
@@ -16,7 +16,7 @@#include <linux/platform_device.h> -#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) +#define MFD_ARRAY_SIZE (arr) (arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ { \
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 34 lines · Lee Jones
Quoted 32 lines · Rhyland Klein
MFD_ARRAY_SIZE()would not accurately return 0 if the passed parameter was NULL. Fix this so thatnum_resourceswill accurately be 0 in the case that_resis NULL.cc Lee Jones <[email protected]>cc Laxman Dewangan <[email protected]>Signed-off-by Rhyland Klein <[email protected]>--- include/linux/mfd/core.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)include/linux/mfd/core.h +2
-2@@ -18,11 +18,11 @@#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) -#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ +#define MFD_CELL_ALL (_name, _nres, _res, _pdata, _id, _compat, _match) \ { \ .name = (_name), \ .resources = (_res), \ - .num_resources = MFD_ARRAY_SIZE((_res)), \ + .num_resources = (_nres), \ .platform_data = (_pdata), \ .pdata_size = MFD_ARRAY_SIZE((_pdata)), \ .of_compatible = (_compat), \@@ -31,16 +31,19 @@ }
Quoted 7 lines
include/linux/mfd/core.h line 35
Quoted 4 lines
include/linux/mfd/core.h +2
-1#define OF_MFD_CELL (_name, _res, _pdata, _id, _compat) \ - MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, NULL) \ + MFD_CELL_ALL(_name, MFD_ARRAY_SIZE((_res)), _res, \ + _pdata, _id, _compat, NULL) \I'm confused. Why would it be any different just by changing the call site of
MFD_ARRAY_SIZE?
It isn't different, but for MFD_CELL_NAME, it explicitly passes 0 instead of using MFD_ARRAY_SIZE, as its the only place that doesn't expect to have resources.
Quoted 2 lines
And what about .platform_data?
This crashed for me (without the change) at :
mfd_add_device():
for (r = 0; r < cell->num_resources; r++) {
res[r].name = cell->resources[r].name;
res[r].flags = cell->resources[r].flags;where dereferencing cell->resources[0] when there are no resources. I guess the platform_data could do the same, but I didn't run into it.
Quoted 9 lines
How about this change instead?
include/linux/mfd/core.h +0
-0
include/linux/mfd/core.h line 22
Quoted 8 lines
include/linux/mfd/core.h +1
-1@@ -16,7 +16,7 @@#include <linux/platform_device.h> -#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) +#define MFD_ARRAY_SIZE (arr) (arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ { \
That was my first thought too. However, I see this when I try to compile that:
In file included from drivers/mfd/max77620.c:18:0:include/linux/mfd/core.h:19:34: warning: the address of ‘gpio_resources’ will always evaluate as ‘true’ [-Waddress]
#define MFD_ARRAY_SIZE(arr) (arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)
7 different times. This patch was the only way I seemed to be able to WAR around compile time warnings.
-rhyland
Signature · 1 line
nvpublic
Quoted 85 lines · Rhyland Klein
Quoted 34 lines · Lee Jones
Quoted 32 lines · Rhyland Klein
MFD_ARRAY_SIZE()would not accurately return 0 if the passed parameter was NULL. Fix this so thatnum_resourceswill accurately be 0 in the case that_resis NULL.cc Lee Jones <[email protected]>cc Laxman Dewangan <[email protected]>Signed-off-by Rhyland Klein <[email protected]>--- include/linux/mfd/core.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)include/linux/mfd/core.h +2
-2@@ -18,11 +18,11 @@#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) -#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ +#define MFD_CELL_ALL (_name, _nres, _res, _pdata, _id, _compat, _match) \ { \ .name = (_name), \ .resources = (_res), \ - .num_resources = MFD_ARRAY_SIZE((_res)), \ + .num_resources = (_nres), \ .platform_data = (_pdata), \ .pdata_size = MFD_ARRAY_SIZE((_pdata)), \ .of_compatible = (_compat), \@@ -31,16 +31,19 @@ }Quoted 7 lines
include/linux/mfd/core.h line 35
Quoted 4 lines
include/linux/mfd/core.h +2
-1#define OF_MFD_CELL (_name, _res, _pdata, _id, _compat) \ - MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, NULL) \ + MFD_CELL_ALL(_name, MFD_ARRAY_SIZE((_res)), _res, \ + _pdata, _id, _compat, NULL) \I'm confused. Why would it be any different just by changing the call site of
MFD_ARRAY_SIZE?It isn't different, but for
MFD_CELL_NAME, it explicitly passes 0 instead of usingMFD_ARRAY_SIZE, as its the only place that doesn't expect to have resources.Quoted 2 lines
And what about .platform_data?
This crashed for me (without the change) at :
mfd_add_device():for (r = 0; r < cell->num_resources; r++) { res[r].name = cell->resources[r].name; res[r].flags = cell->resources[r].flags;where dereferencing cell->resources[0] when there are no resources. I guess the
platform_datacould do the same, but I didn't run into it.Quoted 9 lines
How about this change instead?
include/linux/mfd/core.h +0
-0include/linux/mfd/core.h line 22
Quoted 8 lines
include/linux/mfd/core.h +1
-1@@ -16,7 +16,7 @@#include <linux/platform_device.h> -#define MFD_ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) +#define MFD_ARRAY_SIZE (arr) (arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)#define MFD_CELL_ALL (_name, _res, _pdata, _id, _compat, _match) \ { \That was my first thought too. However, I see this when I try to compile that:
In file included from
drivers/mfd/max77620.c:18:0:include/linux/mfd/core.h:19:34: warning: the address of ‘gpio_resources’ will always evaluate as ‘true’ [-Waddress]
#defineMFD_ARRAY_SIZE(arr)(arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)
Quoted 5 lines
7 different times. This patch was the only way I seemed to be able to WAR around compile time warnings.
-rhyland
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
-rhyland
Signature · 1 line
nvpublic
Quoted 6 lines · Rhyland Klein
Quoted 5 lines · Rhyland Klein
Quoted 4 lines · Lee Jones
Quoted 2 lines · Rhyland Klein
#define MFD_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Review
Quoted 9 lines
(quoted diff) +2
-2-#define MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, _match) \ +#define MFD_CELL_ALL(_name, _nres, _res, _pdata, _id, _compat, _match) \ { \ .name = (_name), \ .resources = (_res), \ - .num_resources = MFD_ARRAY_SIZE((_res)), \ + .num_resources = (_nres), \ .platform_data = (_pdata), \ .pdata_size = MFD_ARRAY_SIZE((_pdata)), \
The pdata_size initialization is also not correct. This is not the array count but the size of the platform data which is passed. Should be sizeof((_pdata))
Quoted 15 lines
Quoted 15 lines
#define MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, _match) \ { \That was my first thought too. However, I see this when I try to compile that:
In file included from
drivers/mfd/max77620.c:18:0:include/linux/mfd/core.h:19:34: warning: the address of ‘gpio_resources’ will always evaluate as ‘true’ [-Waddress]
#defineMFD_ARRAY_SIZE(arr)(arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)7 different times. This patch was the only way I seemed to be able to WAR around compile time warnings.
Quoted 7 lines
Quoted 2 lines
-rhyland
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commit e60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>
mfd: ab8500: Provide a small example using new MFD cell MACROs
***/
Should we have something MFD_CELL_RES, MFD_CELL_RES_PDATA, MFD_CELL_PDATA, for more common user and not to pass the NULL here.
Quoted 49 lines · Laxman Dewangan
Quoted 4 lines · Rhyland Klein
Quoted 3 lines · Rhyland Klein
Quoted 2 lines · Lee Jones
On Thu, 18 Feb 2016, Rhyland Klein wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Review
Quoted 10 lines
#define
MFD_ARRAY_SIZE(arr)(sizeof(arr) / sizeof((arr)[0]))(quoted diff) +2
-2-#define MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, _match) \ +#define MFD_CELL_ALL(_name, _nres, _res, _pdata, _id, _compat, _match) \ { \ .name = (_name), \ .resources = (_res), \ - .num_resources = MFD_ARRAY_SIZE((_res)), \ + .num_resources = (_nres), \ .platform_data = (_pdata), \ .pdata_size = MFD_ARRAY_SIZE((_pdata)), \The
pdata_sizeinitialization is also not correct. This is not the array count but the size
of the platform data which is passed. Should be sizeof((_pdata))Quoted 14 lines
Quoted 14 lines
#define MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, _match) \ { \That was my first thought too. However, I see this when I try to compile that:
In file included from
drivers/mfd/max77620.c:18:0:include/linux/mfd/core.h:19:34: warning: the address of ‘gpio_resources’ will always evaluate as ‘true’ [-Waddress]
#defineMFD_ARRAY_SIZE(arr)(arr ? (sizeof(arr) / sizeof((arr)[0])) : 0)7 different times. This patch was the only way I seemed to be able to WAR around compile time warnings.
Quoted 7 lines
Quoted 2 lines
-rhyland
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commite60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>
Quoted 6 lines
mfd: ab8500: Provide a small example using new MFD cell MACROs
***/
Should we have something
MFD_CELL_RES,MFD_CELL_RES_PDATA,MFD_CELL_PDATA, for more common user and not to pass the NULL here.
I'll have a re-think about this.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Hi Lee,
Quoted 14 lines · Lee Jones
Quoted 12 lines · Laxman Dewangan
Quoted 5 lines · Rhyland Klein
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commite60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>
Quoted 7 lines
Quoted 6 lines
mfd: ab8500: Provide a small example using new MFD cell MACROs
***/
Should we have something
MFD_CELL_RES,MFD_CELL_RES_PDATA,MFD_CELL_PDATA, for more common user and not to pass the NULL here.I'll have a re-think about this.
Did you get chance to look into this? Probably, I need to send my mfd series once this get fixed before that series applied.
Quoted 17 lines · Laxman Dewangan
Quoted 16 lines · Lee Jones
Quoted 14 lines · Laxman Dewangan
Quoted 5 lines · Rhyland Klein
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commite60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>mfd: ab8500: Provide a small example using new MFD cell MACROs
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
***/
Should we have something
MFD_CELL_RES,MFD_CELL_RES_PDATA,MFD_CELL_PDATA, for more common user and not to pass the NULL here.I'll have a re-think about this.
Did you get chance to look into this? Probably, I need to send my mfd series once this get fixed before that series applied.
Nothing is going to happen until v4.6 now. It's too late in the release cycle to be making such a significant addition, and I'd like the change to sit in -next for a good while before going in.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 20 lines · Lee Jones
Quoted 19 lines · Laxman Dewangan
Quoted 18 lines · Lee Jones
Quoted 16 lines · Laxman Dewangan
Quoted 5 lines · Rhyland Klein
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commite60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>mfd: ab8500: Provide a small example using new MFD cell MACROs
***/
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Should we have something
MFD_CELL_RES,MFD_CELL_RES_PDATA,MFD_CELL_PDATA, for more common user and not to pass the NULL here.I'll have a re-think about this.
Did you get chance to look into this? Probably, I need to send my mfd series once this get fixed before that series applied.
Nothing is going to happen until v4.6 now. It's too late in the release cycle to be making such a significant addition, and I'd like the change to sit in -next for a good while before going in.
OK, so can I use the local initializations in my max77620 patches and resend? Then later we can have cleanups for part only?
This is because if we get in next release then there is some other sub modules of the max77620 like clocks, watchdog, power etc which can go on their subsystem if common header is available.
Sorry if I am asking too much..
Quoted 35 lines · Laxman Dewangan
Quoted 20 lines · Lee Jones
Quoted 19 lines · Laxman Dewangan
Quoted 18 lines · Lee Jones
Quoted 16 lines · Laxman Dewangan
Quoted 5 lines · Rhyland Klein
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commite60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>mfd: ab8500: Provide a small example using new MFD cell MACROs
***/
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Should we have something
MFD_CELL_RES,MFD_CELL_RES_PDATA,MFD_CELL_PDATA, for more common user and not to pass the NULL here.I'll have a re-think about this.
Did you get chance to look into this? Probably, I need to send my mfd series once this get fixed before that series applied.
Nothing is going to happen until v4.6 now. It's too late in the release cycle to be making such a significant addition, and I'd like the change to sit in -next for a good while before going in.
OK, so can I use the local initializations in my max77620 patches and resend?
Then later we can have cleanups for part only?
Quoted 5 lines
This is because if we get in next release then there is some other sub modules of the max77620 like clocks, watchdog, power etc which can go on their subsystem if common header is available.
Sorry if I am asking too much..
For quick accptance, just submit using the normal un-MACRO'ed structure.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 36 lines · Lee Jones
Quoted 34 lines · Laxman Dewangan
Quoted 20 lines · Lee Jones
Quoted 19 lines · Laxman Dewangan
Quoted 18 lines · Lee Jones
Quoted 16 lines · Laxman Dewangan
Quoted 5 lines · Rhyland Klein
Did you not see warnings like this when you compiled the kernel? Did you find a different approach than what I proposed above to deal with it? I'd like to get this in soon so that when the max77620 drivers are all in and using it, it should be functional.
I think the following change also crash in runtime:
/***
commite60a946f05db2cac857025da6ffb72df48d3be54
Author: Lee Jones <[email protected]>mfd: ab8500: Provide a small example using new MFD cell MACROs
***/
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Should we have something
MFD_CELL_RES,MFD_CELL_RES_PDATA,MFD_CELL_PDATA, for more common user and not to pass the NULL here.I'll have a re-think about this.
Did you get chance to look into this? Probably, I need to send my mfd series once this get fixed before that series applied.
Nothing is going to happen until v4.6 now. It's too late in the release cycle to be making such a significant addition, and I'd like the change to sit in -next for a good while before going in.
OK, so can I use the local initializations in my max77620 patches and resend?
Then later we can have cleanups for part only?
Quoted 7 lines
Quoted 5 lines
This is because if we get in next release then there is some other sub modules of the max77620 like clocks, watchdog, power etc which can go on their subsystem if common header is available.
Sorry if I am asking too much..
For quick accptance, just submit using the normal un-MACRO'ed structure.
Thanks, I had sent V9 version of the MAX77620 which used normal un-MACROed version.