Skip to contentSkip to conversation

x86/sfi: Enable enumeration of SD devices

bug report Superseded Dan Carpenter 5 participants 25 messages Jul 15, 2016 – Sep 9, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices" from Jul 12, 2016, leads to the following static checker warning:

	arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
	warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c

   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name, SFI_NAME_LEN);
   418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk = %d, addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is a macro calling a function pointer. None of the functions return error pointers. Some return NULL on error but some return NULL on success.

427 if (IS_ERR(pdata))
428 return;
429
430 /* Nothing we can do with this for now */
431 sd_info.platform_data = pdata;
432

regards,
dan carpenter

#1 lore raw
Quoted 26 lines · Dan Carpenter

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices" from Jul 12, 2016, leads to the following static checker warning:

	arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
	warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c
   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name, SFI_NAME_LEN); 418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk = %d, addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is a macro calling a function pointer.  None of the functions return error pointers.  Some return NULL on error but some return NULL on success.

Quoted 6 lines

   427          if (IS_ERR(pdata))
   428                  return;
   429
   430          /* Nothing we can do with this for now */ 431          sd_info.platform_data = pdata; 432

Thanks for catching up this. At some point in the future I will re-check all those so called "device lib" files to be aligned to one standard. Of course you may propose a patch if you feel you can do it.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#2 lore raw
In reply to Dan Carpenter
Quoted 34 lines · Andy Shevchenko
Quoted 26 lines · Dan Carpenter

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices" from Jul 12, 2016, leads to the following static checker warning:

	arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
	warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c
   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name, SFI_NAME_LEN); 418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk = %d, addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is a macro calling a function pointer.  None of the functions return error pointers.  Some return NULL on error but some return NULL on success.

Quoted 6 lines

   427          if (IS_ERR(pdata))
   428                  return;
   429
   430          /* Nothing we can do with this for now */ 431          sd_info.platform_data = pdata; 432

Quoted 3 lines

Thanks for catching up this. At some point in the future I will re-check all those so called "device lib" files to be aligned to one standard. Of course you may propose a patch if you feel you can do it.

I'm a temporary haitus from work but what's the standard supposed to be?

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Dan Carpenter

+ David, Sathya

Quoted 39 lines · Dan Carpenter
Quoted 38 lines · Andy Shevchenko
Quoted 35 lines · Dan Carpenter

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices"
from Jul 12, 2016, leads to the following static checker warning:

	arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
	warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c
   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name, SFI_NAME_LEN); 418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk > > > %d, addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is a macro calling a function pointer.  None of the functions return error pointers.  Some return NULL on error but some return NULL
on success.

   427          if (IS_ERR(pdata))
   428                  return;
   429
   430          /* Nothing we can do with this for now */ 431          sd_info.platform_data = pdata; 432

Quoted 8 lines
Quoted 5 lines

Thanks for catching up this. At some point in the future I will re- check
all those so called "device lib" files to be aligned to one standard. Of
course you may propose a patch if you feel you can do it.

I'm a temporary haitus from work but what's the standard supposed to be?

I've checked all upstreamed platform modules (arch/x86/platform/intel- mid/device_libs/) and noticed that not a single one returns ERR_PTR.

Though I think the idea was to provide a way to fail initialization in some cases where hardware must be initialized properly. Maybe David or Sathya can shed a light on this.

If we decide to change that it should be done for all so called device handlers in sfi.c.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#4 lore raw
In reply to Dan Carpenter

Hi Andy/Dan,

Thanks for catching this bug. As Andy mentioned, this code is written in this manner to let the get_platform_data() function pointer to return the error value on initialization failure. But it has never been used properly in any of the existing code. So my suggestion is either change the platform_lib code to return ERR_PTR on failure or change the intel_mid_sfi_get_pdata to check for NULL as well. Since all the use case of intel_mid_sfi_get_pdata are void functions, I would prefer to go with second solution. Please let me know your comments.

arch/x86/platform/intel-mid/sfi.c +4 -4
index 051d264..a6bd275 100644
@@ -336,7 +336,7 @@ static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry,
        pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
                pentry->name, pentry->irq);
        pdata = intel_mid_sfi_get_pdata(dev, pentry);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        pdev = platform_device_alloc(pentry->name, 0);
@@ -371,7 +371,7 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
                spi_info.chip_select);
 
        pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        spi_info.platform_data = pdata;
@@ -398,7 +398,7 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
                i2c_info.addr);
        pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
        i2c_info.platform_data = pdata;
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        if (dev->delay)
@@ -424,7 +424,7 @@ static void __init sfi_handle_sd_dev(struct sfi_device_table_entry *pentry,
                 sd_info.max_clk,
                 sd_info.addr);
        pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        /* Nothing we can do with this for now */

Thanks and regards,
Sathyanarayanan KN

________________________________________
From: Andy Shevchenko [[email protected]]
Sent: Sunday, August 28, 2016 6:31 AM
To: Dan Carpenter
Cc: [email protected]; David Cohen; Kuppuswamy, Sathyanarayanan
Subject: Re: [bug report] x86/sfi: Enable enumeration of SD devices

+ David, Sathya

Quoted 39 lines · Dan Carpenter
Quoted 38 lines · Andy Shevchenko
Quoted 35 lines · Dan Carpenter

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices"
from Jul 12, 2016, leads to the following static checker warning:

arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c

   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name, SFI_NAME_LEN);
   418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk > > > %d,
addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is a macro calling a function pointer. None of the functions return error pointers. Some return NULL on error but some return NULL
on success.

   427          if (IS_ERR(pdata))
   428                  return;
   429
   430          /* Nothing we can do with this for now */
   431          sd_info.platform_data = pdata;
   432
Quoted 8 lines
Quoted 5 lines

Thanks for catching up this. At some point in the future I will re- check
all those so called "device lib" files to be aligned to one standard. Of
course you may propose a patch if you feel you can do it.

I'm a temporary haitus from work but what's the standard supposed to be?

I've checked all upstreamed platform modules (arch/x86/platform/intel- mid/device_libs/) and noticed that not a single one returns ERR_PTR.

Though I think the idea was to provide a way to fail initialization in some cases where hardware must be initialized properly. Maybe David or Sathya can shed a light on this.

If we decide to change that it should be done for all so called device handlers in sfi.c.

--
Andy Shevchenko <[email protected]> Intel Finland Oy

#5 lore raw
In reply to Dan Carpenter
Quoted 18 lines · Sathyanarayanan

Hi Andy/Dan,

Thanks for catching this bug. As Andy mentioned, this code is written in this manner to let the get_platform_data() function pointer to return the error value on initialization failure. But it has never been used properly in any of the existing code. So my suggestion is either change the platform_lib code to return ERR_PTR on failure or change the intel_mid_sfi_get_pdata to check for NULL as well. Since all the use case of intel_mid_sfi_get_pdata are void functions, I would prefer to go with second solution. Please let me know your comments.

arch/x86/platform/intel-mid/sfi.c +0 -0
index 051d264..a6bd275 100644

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_ipc_dev(struct · line 340

Quoted 6 lines
arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -336,7 +336,7 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,
         pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
                 pentry->name, pentry->irq);
         pdata = intel_mid_sfi_get_pdata(dev, pentry);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))

But this looks wrong.
pdata = NULL is valid case for many devices! In other words pdata is an optional argument to the device drivers.

Quoted 118 lines
arch/x86/platform/intel-mid/sfi.c +0 -0
                 return;


        pdev = platform_device_alloc(pentry->name, 0);

arch/x86/platform/intel-mid/sfi.c +0 -0
@@ -371,7 +371,7 @@ static void __init sfi_handle_spi_dev(struct
 sfi_device_table_entry *pentry,
                 spi_info.chip_select);


        pdata = intel_mid_sfi_get_pdata(dev, &spi_info); -       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;

        spi_info.platform_data = pdata;

arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -398,7 +398,7 @@ static void __init sfi_handle_i2c_dev(struct
 sfi_device_table_entry *pentry,
                 i2c_info.addr);
         pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
         i2c_info.platform_data = pdata;
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                 return;


        if (dev->delay)

arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -424,7 +424,7 @@ static void __init sfi_handle_sd_dev(struct
 sfi_device_table_entry *pentry,
                  sd_info.max_clk,
                  sd_info.addr);
         pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                 return;


        /* Nothing we can do with this for now */

Thanks and regards,
Sathyanarayanan KN

________________________________________
From: Andy Shevchenko [[email protected]]
Sent: Sunday, August 28, 2016 6:31 AM
To: Dan Carpenter
Cc: [email protected]; David Cohen; Kuppuswamy, Sathyanarayanan
Subject: Re: [bug report] x86/sfi: Enable enumeration of SD devices

+ David, Sathya

Quoted 53 lines · Dan Carpenter
Quoted 44 lines · Andy Shevchenko
Quoted 34 lines · Dan Carpenter

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices"
from Jul 12, 2016, leads to the following static checker warning:

  arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
  warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c
   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name, SFI_NAME_LEN);
   418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk > > > > %d, addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is a macro calling a function pointer.  None of the functions
return error pointers.  Some return NULL on error but some return
NULL
on success.

Quoted 6 lines

   427          if (IS_ERR(pdata))
   428                  return;
   429
   430          /* Nothing we can do with this for now */ 431          sd_info.platform_data = pdata; 432

Quoted 6 lines

Thanks for catching up this. At some point in the future I will re-
check
all those so called "device lib" files to be aligned to one standard. Of
course you may propose a patch if you feel you can do it.

Quoted 2 lines

I'm a temporary haitus from work but what's the standard supposed to be?

I've checked all upstreamed platform modules (arch/x86/platform/intel- mid/device_libs/) and noticed that not a single one returns ERR_PTR.

Though I think the idea was to provide a way to fail initialization in some cases where hardware must be initialized properly. Maybe David or Sathya can shed a light on this.

If we decide to change that it should be done for all so called device handlers in sfi.c.

--
Andy Shevchenko <[email protected]> Intel Finland Oy

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#6 lore raw
In reply to Dan Carpenter

Am 30.08.2016 11:46, schrieb Andy Shevchenko:

Quoted 13 lines · Sathyanarayanan
Quoted 12 lines

Hi Andy/Dan,

Thanks for catching this bug. As Andy mentioned, this code is written in this manner to let the get_platform_data() function pointer to return the error value on initialization failure. But it has never been used properly in any of the existing code. So my suggestion is either change the platform_lib code to return ERR_PTR on failure or change the intel_mid_sfi_get_pdata to check for NULL as well. Since all the use case of intel_mid_sfi_get_pdata are void functions, I would prefer to go with second solution. Please let me know your comments.

Quoted 17 lines

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_ipc_dev(struct · line 340

Quoted 12 lines
arch/x86/platform/intel-mid/sfi.c +1 -1
index 051d264..a6bd275 100644
@@ -336,7 +336,7 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,
        pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
                pentry->name, pentry->irq);
        pdata = intel_mid_sfi_get_pdata(dev, pentry);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))

But this looks wrong.
pdata = NULL is valid case for many devices! In other words pdata is an optional argument to the device drivers.

Yep, the way is wrong.
NULL can say: get_platform_data does not exists
or get_platform_data() returned NULL (what ever that means).

IMHO it feels better to drop the define and replace it with a proper function call and error.

#define intel_mid_sfi_get_pdata(dev, priv)      \
         ((dev)->get_platform_data ? (dev)->get_platform_data(priv) : NULL)

void *fkt(struct devs_id *dev, void *info)

{
     if ( ! dev->get_platform_data)
	  return ERR_PTR(-ENOSYS);

	return dev->get_platform_data(info);
}

just my 2 cents,

re,
wh

Quoted 119 lines
Quoted 118 lines
arch/x86/platform/intel-mid/sfi.c +0 -0
                return;
 
        pdev = platform_device_alloc(pentry->name, 0);
arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -371,7 +371,7 @@ static void __init sfi_handle_spi_dev(struct
 sfi_device_table_entry *pentry,
                spi_info.chip_select);
 
        pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        spi_info.platform_data = pdata;
arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -398,7 +398,7 @@ static void __init sfi_handle_i2c_dev(struct
 sfi_device_table_entry *pentry,
                i2c_info.addr);
        pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
        i2c_info.platform_data = pdata;
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        if (dev->delay)
arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -424,7 +424,7 @@ static void __init sfi_handle_sd_dev(struct
 sfi_device_table_entry *pentry,
                 sd_info.max_clk,
                 sd_info.addr);
        pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))
                return;
 
        /* Nothing we can do with this for now */

Thanks and regards,
Sathyanarayanan KN

________________________________________
From: Andy Shevchenko [[email protected]]
Sent: Sunday, August 28, 2016 6:31 AM
To: Dan Carpenter
Cc: [email protected]; David Cohen; Kuppuswamy, Sathyanarayanan
Subject: Re: [bug report] x86/sfi: Enable enumeration of SD devices

+ David, Sathya

Quoted 53 lines · Dan Carpenter
Quoted 44 lines · Andy Shevchenko
Quoted 34 lines · Dan Carpenter

Hello Andy Shevchenko,

The patch 05f310e26fe9: "x86/sfi: Enable enumeration of SD devices"
from Jul 12, 2016, leads to the following static checker warning:

arch/x86/platform/intel-mid/sfi.c:427 sfi_handle_sd_dev()
warn: 'pdata' isn't an ERR_PTR

arch/x86/platform/intel-mid/sfi.c

   416          memset(&sd_info, 0, sizeof(sd_info));
   417          strncpy(sd_info.name, pentry->name,
SFI_NAME_LEN);
   418          sd_info.bus_num = pentry->host_num;
   419          sd_info.max_clk = pentry->max_freq;
   420          sd_info.addr = pentry->addr;
   421          pr_debug("SD bus = %d, name = %16.16s, max_clk >>>>> %d,
addr = 0x%x\n",
   422                   sd_info.bus_num,
   423                   sd_info.name,
   424                   sd_info.max_clk,
   425                   sd_info.addr);
   426          pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is a macro calling a function pointer. None of the functions
return error pointers. Some return NULL on error but some return
NULL
on success.

Quoted 6 lines
   427          if (IS_ERR(pdata))
   428                  return;
   429
   430          /* Nothing we can do with this for now */
   431          sd_info.platform_data = pdata;
   432
Quoted 6 lines

Thanks for catching up this. At some point in the future I will re-
check
all those so called "device lib" files to be aligned to one standard. Of
course you may propose a patch if you feel you can do it.

Quoted 2 lines

I'm a temporary haitus from work but what's the standard supposed to be?

I've checked all upstreamed platform modules (arch/x86/platform/intel- mid/device_libs/) and noticed that not a single one returns ERR_PTR.

Though I think the idea was to provide a way to fail initialization in some cases where hardware must be initialized properly. Maybe David or Sathya can shed a light on this.

If we decide to change that it should be done for all so called device handlers in sfi.c.

--
Andy Shevchenko <[email protected]> Intel Finland Oy

#7 lore raw
In reply to Dan Carpenter
Quoted 41 lines · walter harms

Am 30.08.2016 11:46, schrieb Andy Shevchenko:

Quoted 29 lines
Quoted 26 lines · Sathyanarayanan

Hi Andy/Dan,

Thanks for catching this bug. As Andy mentioned, this code is written
in this manner to let the get_platform_data() function pointer to return the error value on initialization failure. But it has never been used properly in any of the existing code. So my suggestion is
either change the platform_lib code to return ERR_PTR on failure or
change the intel_mid_sfi_get_pdata to check for NULL as well. Since
all the use case of intel_mid_sfi_get_pdata are void functions, I would prefer to go with second solution. Please let me know your comments.

arch/x86/platform/intel-mid/sfi.c +0 -0
index 051d264..a6bd275 100644
@@ -336,7 +336,7 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,
         pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
                 pentry->name, pentry->irq);
Quoted 9 lines

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_ipc_dev(struct · line 340

Quoted 3 lines
arch/x86/platform/intel-mid/sfi.c +1 -1
         pdata = intel_mid_sfi_get_pdata(dev, pentry);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))

But this looks wrong.
pdata = NULL is valid case for many devices! In other words pdata is an
optional argument to the device drivers.

Quoted 6 lines

Yep, the way is wrong.
NULL can say: get_platform_data does not exists
or get_platform_data() returned NULL (what ever that means).

IMHO it feels better to drop the define and replace it with a proper function call and error.

Yeah, this direction looks better, thanks.

Quoted 34 lines

#define intel_mid_sfi_get_pdata(dev, priv)      \
         ((dev)->get_platform_data ? (dev)->get_platform_data(priv) :
NULL)

void *fkt(struct devs_id *dev, void *info)
{
     if ( ! dev->get_platform_data)

	  return ERR_PTR(-ENOSYS);

	return dev->get_platform_data(info);
}
Quoted 19 lines
Quoted 18 lines

I've checked all upstreamed platform modules (arch/x86/platform/intel-
mid/device_libs/) and noticed that not a single one returns ERR_PTR.

Though I think the idea was to provide a way to fail initialization in
some cases where hardware must be initialized properly. Maybe David or
Sathya can shed a light on this.

If we decide to change that it should be done for all so called device
handlers in sfi.c.

--
Andy Shevchenko <[email protected]> Intel Finland Oy

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#8 lore raw
In reply to Dan Carpenter
Quoted 37 lines · Andy Shevchenko
Quoted 36 lines · walter harms

Am 30.08.2016 11:46, schrieb Andy Shevchenko:

Quoted 35 lines
Quoted 22 lines · Sathyanarayanan

Hi Andy/Dan,

Thanks for catching this bug. As Andy mentioned, this code is written
in this manner to let the get_platform_data() function pointer to return the error value on initialization failure. But it has never been used properly in any of the existing code. So my suggestion is
either change the platform_lib code to return ERR_PTR on failure or
change the intel_mid_sfi_get_pdata to check for NULL as well. Since
all the use case of intel_mid_sfi_get_pdata are void functions, I would prefer to go with second solution. Please let me know your comments.

arch/x86/platform/intel-mid/sfi.c +0 -0
index 051d264..a6bd275 100644

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_ipc_dev(struct · line 340

Quoted 6 lines
arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -336,7 +336,7 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,
         pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
                 pentry->name, pentry->irq);
         pdata = intel_mid_sfi_get_pdata(dev, pentry);
-       if (IS_ERR(pdata))
+       if (IS_ERR_OR_NULL(pdata))

But this looks wrong.
pdata = NULL is valid case for many devices! In other words pdata is an
optional argument to the device drivers.

Quoted 7 lines
Quoted 6 lines

Yep, the way is wrong.
NULL can say: get_platform_data does not exists
or get_platform_data() returned NULL (what ever that means).

IMHO it feels better to drop the define and replace it with a proper function call and error.

Yeah, this direction looks better, thanks.

I missed the generic null scenario. Thanks for pointing it out Andy.

IMO, Main problem here is, In some scenarios get_platform_data returns NULL on error case and in some cases it return NULL for no platform data case.

For example, in following function, returning NULL on gpio_base = -1 and when nr >= PCAL9555A_NUM is incorrect. I think in both these scenarios valid behavior is to stop the device creation process. Creating an i2c device without validi irq number or gpio number is incorrect.

So after investigating it bit more, I think its more appropriate to fix these error cases in device_libs dir. Let me know your comments.

static void __init *pcal9555a_platform_data(void *info)

{
         struct i2c_board_info *i2c_info = info;
         char *type = i2c_info->type;
         struct pca953x_platform_data *pcal9555a;
         char base_pin_name[SFI_NAME_LEN + 1];
         char intr_pin_name[SFI_NAME_LEN + 1];
         int gpio_base, intr;

         snprintf(base_pin_name, sizeof(base_pin_name), "%s_base", type);
         snprintf(intr_pin_name, sizeof(intr_pin_name), "%s_int", type);

         gpio_base = get_gpio_by_name(base_pin_name);
         intr = get_gpio_by_name(intr_pin_name);

         /* Check if the SFI record valid */
         if (gpio_base = -1)
                 return NULL;

         if (nr >= PCAL9555A_NUM) {
                 pr_err("%s: Too many instances, only %d supported\n", 
__func__,
                        PCAL9555A_NUM);
                 return NULL;
         }

         pcal9555a = &pcal9555a_pdata[nr++];
         pcal9555a->gpio_base = gpio_base;

         if (intr >= 0) {
                 i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
                 pcal9555a->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
         } else {
                 i2c_info->irq = -1;
                 pcal9555a->irq_base = -1;
         }

         strcpy(type, "pcal9555a");
         return pcal9555a;
}
Quoted 32 lines
Quoted 32 lines
#define intel_mid_sfi_get_pdata(dev, priv)      \
          ((dev)->get_platform_data ? (dev)->get_platform_data(priv) :

NULL)

void *fkt(struct devs_id *dev, void *info)

{
      if ( ! dev->get_platform_data)
	  return ERR_PTR(-ENOSYS);

	return dev->get_platform_data(info);
}
Quoted 18 lines
Quoted 18 lines

I've checked all upstreamed platform modules (arch/x86/platform/intel-
mid/device_libs/) and noticed that not a single one returns ERR_PTR.

Though I think the idea was to provide a way to fail initialization in
some cases where hardware must be initialized properly. Maybe David or
Sathya can shed a light on this.

If we decide to change that it should be done for all so called device
handlers in sfi.c.

--
Andy Shevchenko <[email protected]> Intel Finland Oy

Signature · 2 lines
Sathyanarayanan Kuppuswamy
Android kernel developer
#9 lore raw

PATCH 1/1 intel-mid: Fix sfi get_platform_data() return value issues

According to the intel_mid_sfi_get_pdata() function definition, get_platform_data() function should returns NULL on no platform data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

---
 .../platform/intel-mid/device_libs/platform_lis331.c    | 13 +++++++++----
 .../platform/intel-mid/device_libs/platform_max7315.c   |  9 ++++++---
 .../platform/intel-mid/device_libs/platform_mpu3050.c   |  7 +++++--
 .../platform/intel-mid/device_libs/platform_pcal9555a.c |  8 +++++---
 .../platform/intel-mid/device_libs/platform_tca6416.c   |  7 +++++--
 arch/x86/platform/intel-mid/sfi.c                       | 17 +++++++++++++----
 6 files changed, 43 insertions(+), 18 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +9 -4
index a35cf91..2fd200b 100644
@@ -21,10 +21,15 @@ static void __init *lis331dl_platform_data(void *info)
 	int intr = get_gpio_by_name("accel_int");
 	int intr2nd = get_gpio_by_name("accel_2");
 
-	if (intr < 0)
-		return NULL;
-	if (intr2nd < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt1 error\n", __func__);
+		return ERR_PTR(intr);
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: invalid interrupt2 error\n", __func__);
+		return ERR_PTR(intr2nd);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +6 -3
index 6e075af..cc20dfc 100644
@@ -31,7 +31,7 @@ static void __init *max7315_platform_data(void *info)
 	if (nr = MAX7315_NUM) {
 		pr_err("too many max7315s, we only support %d\n",
 				MAX7315_NUM);
-		return NULL;
+		return ERR_PTR(-ENODEV);
 	}
 	/* we have several max7315 on the board, we only need load several
 	 * instances of the same pca953x driver to cover them
@@ -48,8 +48,11 @@ static void __init *max7315_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);
+	}
+
 	max7315->gpio_base = gpio_base;
 	if (intr != -1) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +5 -2
index ee22864..2008824 100644
@@ -19,10 +19,13 @@ static void *mpu3050_platform_data(void *info)
 	struct i2c_board_info *i2c_info = info;
 	int intr = get_gpio_by_name("mpu3050_int");
 
-	if (intr < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt error\n", __func__);
+		return ERR_PTR(intr);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
+
 	return NULL;
 }
 
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +5 -3
index 429a941..97e92a2 100644
@@ -41,13 +41,15 @@ static void __init *pcal9555a_platform_data(void *info)
 	intr = get_gpio_by_name(intr_pin_name);
 
 	/* Check if the SFI record valid */
-	if (gpio_base = -1)
-		return NULL;
+	if (gpio_base = -1) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);
+	}
 
 	if (nr >= PCAL9555A_NUM) {
 		pr_err("%s: Too many instances, only %d supported\n", __func__,
 		       PCAL9555A_NUM);
-		return NULL;
+		return ERR_PTR(-ENODEV);
 	}
 
 	pcal9555a = &pcal9555a_pdata[nr++];
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +5 -2
index 4f41372..2796956 100644
@@ -34,8 +34,11 @@ static void *tca6416_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);
+	}
+
 	tca6416.gpio_base = gpio_base;
 	if (intr >= 0) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/sfi.c +13 -4
index 051d264..8e7361f 100644
@@ -335,9 +335,12 @@ static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry,
 
 	pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
 		pentry->name, pentry->irq);
+
 	pdata = intel_mid_sfi_get_pdata(dev, pentry);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("ipc_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	pdev = platform_device_alloc(pentry->name, 0);
 	if (pdev = NULL) {
@@ -371,8 +374,10 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
 		spi_info.chip_select);
 
 	pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("spi_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	spi_info.platform_data = pdata;
 	if (dev->delay)
@@ -398,8 +403,10 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
 		i2c_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
 	i2c_info.platform_data = pdata;
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("i2c_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	if (dev->delay)
 		intel_scu_i2c_device_register(pentry->host_num, &i2c_info);
@@ -424,8 +431,10 @@ static void __init sfi_handle_sd_dev(struct sfi_device_table_entry *pentry,
 		 sd_info.max_clk,
 		 sd_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("sd_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	/* Nothing we can do with this for now */
 	sd_info.platform_data = pdata;
Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH 1/1] intel-mid: Fix sfi get_platform_data() return value issues

Quoted 6 lines · Kuppuswamy Sathyanarayanan

According to the intel_mid_sfi_get_pdata() function definition, get_platform_data() function should returns NULL on no platform data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

I'm fine with this as long as it doesn't prevent booting.

See also comments below.

Quoted 25 lines

linux.intel.com>
---
 .../platform/intel-mid/device_libs/platform_lis331.c    | 13
+++++++++----
 .../platform/intel-mid/device_libs/platform_max7315.c   |  9 ++++++
---
 .../platform/intel-mid/device_libs/platform_mpu3050.c   |  7 +++++-- .../platform/intel-mid/device_libs/platform_pcal9555a.c |  8 +++++--- .../platform/intel-mid/device_libs/platform_tca6416.c   |  7 +++++-- arch/x86/platform/intel-mid/sfi.c                       | 17
+++++++++++++----

 6 files changed, 43 insertions(+), 18 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +0 -0
index a35cf91..2fd200b 100644
@@ -21,10 +21,15 @@ static void __init *lis331dl_platform_data(void
 *info)
  	int intr = get_gpio_by_name("accel_int");
  	int intr2nd = get_gpio_by_name("accel_2");

arch/x86/platform/intel-mid/device_libs/platform_lis331.c static void __init *lis331dl_platform_data(void *info) · line 25

Quoted 6 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -4
-	if (intr < 0)
-		return NULL;
-	if (intr2nd < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt1 error\n", __func__);

I would rephrase to something like

#define LIS331DL_ACCEL_INT "accel_int"

...

pr_err("%s: Can't find %s GPIO interrupt\n", __func__, LIS331DL_ACCEL_INT);

arch/x86/platform/intel-mid/device_libs/platform_lis331.c static void __init *lis331dl_platform_data(void *info) · line 30

Quoted 5 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +5 -0
+		return ERR_PTR(intr);
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: invalid interrupt2 error\n", __func__);

Ditto.

Quoted 12 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -0
+		return ERR_PTR(intr2nd);
+	}


  i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET; intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;

(quoted diff) +0 -0

mid/device_libs/platform_max7315.c b/arch/x86/platform/intel- mid/device_libs/platform_max7315.c
index 6e075af..cc20dfc 100644

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void · line 34

Quoted 4 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
@@ -31,7 +31,7 @@ static void __init *max7315_platform_data(void
 *info)
  	if (nr = MAX7315_NUM) {
  		pr_err("too many max7315s, we only support %d\n",
  				MAX7315_NUM);

"%s: too many instances, we only support %d\n", __func__, MAX7315_NUM

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void · line 35

Quoted 2 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +1 -1
-		return NULL;
+		return ERR_PTR(-ENODEV);

-ENOMEM

Quoted 9 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
  	}
  	/* we have several max7315 on the board, we only need load

several
   * instances of the same pca953x driver to cover them

arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
@@ -48,8 +48,11 @@ static void __init *max7315_platform_data(void
 *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void *info) · line 53

Quoted 5 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +3 -2
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);

"Unknown GPIO base, falling back to dynamic allocation"

Would it work like that? (Needs more work on patch, perhaps separate patch)

Quoted 15 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -0
+	}
+

  max7315->gpio_base = gpio_base;
  if (intr != -1) {
  i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;

(quoted diff) +0 -0

mid/device_libs/platform_mpu3050.c b/arch/x86/platform/intel- mid/device_libs/platform_mpu3050.c
index ee22864..2008824 100644

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +0 -0
@@ -19,10 +19,13 @@ static void *mpu3050_platform_data(void *info)
  	struct i2c_board_info *i2c_info = info;
  	int intr = get_gpio_by_name("mpu3050_int");

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c static void *mpu3050_platform_data(void *info) · line 23

Quoted 4 lines
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +2 -2
-	if (intr < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt error\n", __func__);

pr_err("%s: Can't find %s GPIO interrupt\n", __func__, MPU3050_INT);

Quoted 19 lines
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +2 -0
+		return ERR_PTR(intr);
+	}


  i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET; +
  return NULL;
 }

(quoted diff) +0 -0

mid/device_libs/platform_pcal9555a.c b/arch/x86/platform/intel- mid/device_libs/platform_pcal9555a.c
index 429a941..97e92a2 100644

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -41,13 +41,15 @@ static void __init *pcal9555a_platform_data(void
 *info)
  	intr = get_gpio_by_name(intr_pin_name);


  /* Check if the SFI record valid */

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c static void __init *pcal9555a_platform_data(void *info) · line 46

Quoted 5 lines
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +3 -2
-	if (gpio_base = -1)
-		return NULL;
+	if (gpio_base = -1) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);

Same as above for gpio_base.

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c

Quoted 8 lines
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +1 -0
+	}


  if (nr >= PCAL9555A_NUM) {
  pr_err("%s: Too many instances, only %d supported\n", __func__,
         PCAL9555A_NUM);

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +1 -1
-		return NULL;
+		return ERR_PTR(-ENODEV);

-ENOMEM

Quoted 13 lines

  }

  pcal9555a = &pcal9555a_pdata[nr++];

(quoted diff) +0 -0

mid/device_libs/platform_tca6416.c b/arch/x86/platform/intel- mid/device_libs/platform_tca6416.c
index 4f41372..2796956 100644

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +0 -0
@@ -34,8 +34,11 @@ static void *tca6416_platform_data(void *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c

Quoted 5 lines
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +3 -2
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);

Same as above for gpio_base.

Quoted 22 lines
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +2 -0
+	}
+

  tca6416.gpio_base = gpio_base;
  if (intr >= 0) {
  i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;

arch/x86/platform/intel-mid/sfi.c +0 -0
index 051d264..8e7361f 100644
@@ -335,9 +335,12 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,


  pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n", pentry->name, pentry->irq);
+
  pdata = intel_mid_sfi_get_pdata(dev, pentry);

arch/x86/platform/intel-mid/sfi.c +2 -1
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("ipc_device: %s: invalid platform data\n",

pentry->name);
  return;

arch/x86/platform/intel-mid/sfi.c

Quoted 1 line
arch/x86/platform/intel-mid/sfi.c +1 -0
+	}

This is actually needs more work. We have duplication in sfi.c and platform_ipc.c.

Quoted 13 lines


  pdev = platform_device_alloc(pentry->name, 0); if (pdev = NULL) {

arch/x86/platform/intel-mid/sfi.c +0 -0
@@ -371,8 +374,10 @@ static void __init sfi_handle_spi_dev(struct
 sfi_device_table_entry *pentry,
  		spi_info.chip_select);


  pdata = intel_mid_sfi_get_pdata(dev, &spi_info);

arch/x86/platform/intel-mid/sfi.c +2 -1
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
 
 
+		pr_err("spi_device: %s: invalid platform data\n",
Quoted 1 line

pentry->name);

Since you print messages in device_libs files I would drop this one because it has no value. OTOH you can move it to debug level and rephrase:

pr_debug("%s: Can't get platform data for %s\n", __func__ [or "SPI ..."], pentry->name);

Quoted 6 lines

  return;

arch/x86/platform/intel-mid/sfi.c +1 -0
+	}


  spi_info.platform_data = pdata;
  if (dev->delay)

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_i2c_dev(struct · line 410

Quoted 9 lines
arch/x86/platform/intel-mid/sfi.c +2 -1
@@ -398,8 +403,10 @@ static void __init sfi_handle_i2c_dev(struct
 sfi_device_table_entry *pentry,
  		i2c_info.addr);
  	pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
  	i2c_info.platform_data = pdata;
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("i2c_device: %s: invalid platform data\n",
 pentry->name);
  		return;

Ditto.

Quoted 6 lines
arch/x86/platform/intel-mid/sfi.c +1 -0
+	}


  if (dev->delay) intel_scu_i2c_device_register(pentry->host_num, &i2c_info);

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_sd_dev(struct · line 439

Quoted 10 lines
arch/x86/platform/intel-mid/sfi.c +3 -1
@@ -424,8 +431,10 @@ static void __init sfi_handle_sd_dev(struct
 sfi_device_table_entry *pentry,
  		 sd_info.max_clk,
  		 sd_info.addr);
  	pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("sd_device: %s: invalid platform data\n",
 pentry->name);
  		return;
+	}

Ditto.

Quoted 3 lines


  /* Nothing we can do with this for now */
  sd_info.platform_data = pdata;

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#11 lore raw

Re: [PATCH 1/1] intel-mid: Fix sfi get_platform_data() return value issues

Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Kuppuswamy Sathyanarayanan

According to the intel_mid_sfi_get_pdata() function definition, get_platform_data() function should returns NULL on no platform data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

I'm fine with this as long as it doesn't prevent booting.

See also comments below.

Thanks for the review. Please find my comments inline.

Quoted 33 lines
Quoted 21 lines

linux.intel.com>

---
  .../platform/intel-mid/device_libs/platform_lis331.c    | 13
+++++++++----
  .../platform/intel-mid/device_libs/platform_max7315.c   |  9 ++++++
---
  .../platform/intel-mid/device_libs/platform_mpu3050.c   |  7 +++++--
  .../platform/intel-mid/device_libs/platform_pcal9555a.c |  8 +++++---
  .../platform/intel-mid/device_libs/platform_tca6416.c   |  7 +++++--
  arch/x86/platform/intel-mid/sfi.c                       | 17
+++++++++++++----
  6 files changed, 43 insertions(+), 18 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +0 -0
index a35cf91..2fd200b 100644

arch/x86/platform/intel-mid/device_libs/platform_lis331.c static void __init *lis331dl_platform_data(void · line 26

Quoted 10 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -4
@@ -21,10 +21,15 @@ static void __init *lis331dl_platform_data(void
 *info)
  	int intr = get_gpio_by_name("accel_int");
  	int intr2nd = get_gpio_by_name("accel_2");
 
-	if (intr < 0)
-		return NULL;
-	if (intr2nd < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt1 error\n", __func__);

I would rephrase to something like

Quoted 7 lines

#define LIS331DL_ACCEL_INT "accel_int"

...

pr_err("%s: Can't find %s GPIO interrupt\n", __func__, LIS331DL_ACCEL_INT);

Agreed. Will be fixed in next patch version.

Quoted 6 lines

arch/x86/platform/intel-mid/device_libs/platform_lis331.c static void __init *lis331dl_platform_data(void *info) · line 30

Quoted 5 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +5 -0
+		return ERR_PTR(intr);
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: invalid interrupt2 error\n", __func__);

Ditto.

Agreed. Will be fixed in next patch version.

Quoted 19 lines
Quoted 13 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -0
+		return ERR_PTR(intr2nd);
+	}
 
  	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;

intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;

(quoted diff) +0 -0

mid/device_libs/platform_max7315.c b/arch/x86/platform/intel- mid/device_libs/platform_max7315.c
index 6e075af..cc20dfc 100644

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void · line 34

Quoted 4 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
@@ -31,7 +31,7 @@ static void __init *max7315_platform_data(void
 *info)
  	if (nr = MAX7315_NUM) {
  		pr_err("too many max7315s, we only support %d\n",
  				MAX7315_NUM);

"%s: too many instances, we only support %d\n", __func__, MAX7315_NUM

Quoted 3 lines

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void · line 35

Quoted 2 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +1 -1
-		return NULL;
+		return ERR_PTR(-ENODEV);

-ENOMEM

Agreed. Will be fixed in next patch version.

Quoted 17 lines
Quoted 6 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
  	}
  	/* we have several max7315 on the board, we only need load

several
* instances of the same pca953x driver to cover them

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void · line 54

Quoted 9 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +3 -2
@@ -48,8 +48,11 @@ static void __init *max7315_platform_data(void
 *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);

"Unknown GPIO base, falling back to dynamic allocation"

Quoted 2 lines

Would it work like that? (Needs more work on patch, perhaps separate patch)

Agreed. Will be fixed in next patch version.

Quoted 16 lines
Quoted 16 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -0
+	}
+
  	max7315->gpio_base = gpio_base;
  	if (intr != -1) {

i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;

(quoted diff) +0 -0

mid/device_libs/platform_mpu3050.c b/arch/x86/platform/intel- mid/device_libs/platform_mpu3050.c
index ee22864..2008824 100644

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +0 -0
@@ -19,10 +19,13 @@ static void *mpu3050_platform_data(void *info)
  	struct i2c_board_info *i2c_info = info;
  	int intr = get_gpio_by_name("mpu3050_int");
 
Quoted 5 lines

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c static void *mpu3050_platform_data(void *info) · line 23

Quoted 4 lines
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +2 -2
-	if (intr < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt error\n", __func__);

pr_err("%s: Can't find %s GPIO interrupt\n", __func__, MPU3050_INT);

Agreed. Will be fixed in next patch version.

Quoted 19 lines
Quoted 19 lines
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +3 -0
+		return ERR_PTR(intr);
+	}
 
  	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
+
  	return NULL;
  }
 
(quoted diff) +0 -0

mid/device_libs/platform_pcal9555a.c b/arch/x86/platform/intel- mid/device_libs/platform_pcal9555a.c
index 429a941..97e92a2 100644

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -41,13 +41,15 @@ static void __init *pcal9555a_platform_data(void
 *info)
  	intr = get_gpio_by_name(intr_pin_name);
 
Quoted 7 lines

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c static void __init *pcal9555a_platform_data(void *info) · line 46

Quoted 6 lines
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +3 -2
  	/* Check if the SFI record valid */
-	if (gpio_base = -1)
-		return NULL;
+	if (gpio_base = -1) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);

Same as above for gpio_base.

Same as above

Quoted 9 lines

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c static void __init *pcal9555a_platform_data(void *info) · line 52

Quoted 8 lines
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +2 -1
+	}
 
  	if (nr >= PCAL9555A_NUM) {
  		pr_err("%s: Too many instances, only %d supported\n",
 __func__,
  		       PCAL9555A_NUM);
-		return NULL;
+		return ERR_PTR(-ENODEV);

-ENOMEM

Agreed. Will be fixed in next patch version.

Quoted 14 lines
Quoted 14 lines
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
  	}

pcal9555a = &pcal9555a_pdata[nr++];

(quoted diff) +0 -0

mid/device_libs/platform_tca6416.c b/arch/x86/platform/intel- mid/device_libs/platform_tca6416.c
index 4f41372..2796956 100644

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +0 -0
@@ -34,8 +34,11 @@ static void *tca6416_platform_data(void *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);
 
Quoted 6 lines

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c static void *tca6416_platform_data(void *info) · line 39

Quoted 5 lines
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +3 -2
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);

Same as above for gpio_base.

Same as above

Quoted 14 lines
Quoted 14 lines
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +2 -0
+	}
+
  	tca6416.gpio_base = gpio_base;
  	if (intr >= 0) {
  		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/sfi.c +0 -0
index 051d264..8e7361f 100644
@@ -335,9 +335,12 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,
 
Quoted 12 lines

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry, · line 343

Quoted 10 lines
arch/x86/platform/intel-mid/sfi.c +4 -1
  	pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
  		pentry->name, pentry->irq);
+
  	pdata = intel_mid_sfi_get_pdata(dev, pentry);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("ipc_device: %s: invalid platform data\n",
 pentry->name);
  		return;
+	}

This is actually needs more work. We have duplication in sfi.c and platform_ipc.c.

Yes. But platform_ipc.c implements custom ipc handler for audio ipc device. Even though there are duplications between custom handler and generic handler in sfi.c, I think its bit early to optimize this. I think we should revisit this once we have one more implementation of custom ipc handler.

Quoted 12 lines
Quoted 12 lines
arch/x86/platform/intel-mid/sfi.c +0 -0
  	pdev = platform_device_alloc(pentry->name, 0);
  	if (pdev = NULL) {
arch/x86/platform/intel-mid/sfi.c +1 -1
@@ -371,8 +374,10 @@ static void __init sfi_handle_spi_dev(struct
 sfi_device_table_entry *pentry,
  		spi_info.chip_select);
 
  	pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
 
Quoted 8 lines

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_spi_dev(struct · line 381

Quoted 2 lines
arch/x86/platform/intel-mid/sfi.c +1 -0
+		pr_err("spi_device: %s: invalid platform data\n",
 pentry->name);

Since you print messages in device_libs files I would drop this one because it has no value. OTOH you can move it to debug level and rephrase:

pr_debug("%s: Can't get platform data for %s\n", __func__ [or "SPI ..."], pentry->name);

Agreed. Will be fixed in next version.

Quoted 4 lines
Quoted 4 lines
arch/x86/platform/intel-mid/sfi.c +1 -0
  		return;
+	}
Quoted 13 lines

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_i2c_dev(struct · line 410

Quoted 12 lines
  	spi_info.platform_data = pdata;
  	if (dev->delay)
arch/x86/platform/intel-mid/sfi.c +2 -1
@@ -398,8 +403,10 @@ static void __init sfi_handle_i2c_dev(struct
 sfi_device_table_entry *pentry,
  		i2c_info.addr);
  	pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
  	i2c_info.platform_data = pdata;
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("i2c_device: %s: invalid platform data\n",
 pentry->name);
  		return;

Ditto.

Same as above.

Quoted 18 lines
Quoted 7 lines
arch/x86/platform/intel-mid/sfi.c +1 -0
+	}
 

if (dev->delay)
intel_scu_i2c_device_register(pentry->host_num,
&i2c_info);

arch/x86/platform/intel-mid/sfi.c static void __init sfi_handle_sd_dev(struct · line 439

Quoted 10 lines
arch/x86/platform/intel-mid/sfi.c +3 -1
@@ -424,8 +431,10 @@ static void __init sfi_handle_sd_dev(struct
 sfi_device_table_entry *pentry,
  		 sd_info.max_clk,
  		 sd_info.addr);
  	pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("sd_device: %s: invalid platform data\n",
 pentry->name);
  		return;
+	}

Ditto.

Same as above.

Quoted 4 lines
Quoted 4 lines
arch/x86/platform/intel-mid/sfi.c +0 -0
  	/* Nothing we can do with this for now */
  	sd_info.platform_data = pdata;
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Android kernel developer
#12 lore raw

Re: [PATCH 1/1] intel-mid: Fix sfi get_platform_data() return value issues

Quoted 17 lines · sathyanarayanan kuppuswamy

--- a/arch/x86/platform/intel-mid/sfi.c

Quoted 8 lines
Quoted 8 lines

+++ b/arch/x86/platform/intel-mid/sfi.c

(quoted diff) +0 -0
@@ -335,9 +335,12 @@ static void __init sfi_handle_ipc_dev(struct
 sfi_device_table_entry *pentry,


   pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n", pentry->name, pentry->irq);
+
   pdata = intel_mid_sfi_get_pdata(dev, pentry);

Quoted 8 lines

Review

Quoted 6 lines
arch/x86/platform/intel-mid/sfi.c +2 -1
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("ipc_device: %s: invalid platform data\n",

pentry->name);
   return;

(quoted diff) +1 -0
+	}

This is actually needs more work. We have duplication in sfi.c and platform_ipc.c.

Quoted 5 lines

Yes. But platform_ipc.c implements custom ipc handler for audio ipc device. Even though there are duplications between custom handler and generic handler in sfi.c, I think its bit early to optimize this. I think we should revisit this once we have one more implementation of custom ipc handler.

Definitely it's out of scope for now.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#13 lore raw

PATCH v2 1/1 intel-mid: Fix sfi get_platform_data() return value issues

In reply to Kuppuswamy Sathyanarayanan

According to the intel_mid_sfi_get_pdata() function definition, get_platform_data() function should returns NULL on no platform data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

---
 .../intel-mid/device_libs/platform_lis331.c        | 22 ++++++++++++++++------
 .../intel-mid/device_libs/platform_max7315.c       | 12 ++++++++----
 .../intel-mid/device_libs/platform_mpu3050.c       | 12 +++++++++---
 .../intel-mid/device_libs/platform_pcal9555a.c     |  7 +++++--
 .../intel-mid/device_libs/platform_tca6416.c       |  6 +++++-
 arch/x86/platform/intel-mid/sfi.c                  | 21 +++++++++++++++++----
 6 files changed, 60 insertions(+), 20 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +16 -6
index a35cf91..393c23e 100644
@@ -14,17 +14,27 @@
 #include <linux/gpio.h>
 #include <asm/intel-mid.h>
 
+#define LIS331DL_ACCEL_INT1	"accel_int"
+#define LIS331DL_ACCEL_INT2	"accel_2"
+
 static void __init *lis331dl_platform_data(void *info)
 {
 	static short intr2nd_pdata;
 	struct i2c_board_info *i2c_info = info;
-	int intr = get_gpio_by_name("accel_int");
-	int intr2nd = get_gpio_by_name("accel_2");
+	int intr = get_gpio_by_name(LIS331DL_ACCEL_INT1);
+	int intr2nd = get_gpio_by_name(LIS331DL_ACCEL_INT2);
+
+	if (intr < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       LIS331DL_ACCEL_INT1);
+		return ERR_PTR(intr);
+	}
 
-	if (intr < 0)
-		return NULL;
-	if (intr2nd < 0)
-		return NULL;
+	if (intr2nd < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       LIS331DL_ACCEL_INT2);
+		return ERR_PTR(intr2nd);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +8 -4
index 6e075af..2cd3c7f 100644
@@ -29,9 +29,9 @@ static void __init *max7315_platform_data(void *info)
 	char intr_pin_name[SFI_NAME_LEN + 1];
 
 	if (nr = MAX7315_NUM) {
-		pr_err("too many max7315s, we only support %d\n",
-				MAX7315_NUM);
-		return NULL;
+		pr_err("%s: too many max7315s, we only support %d\n",
+		       __func__, MAX7315_NUM);
+		return ERR_PTR(-ENOMEM);
 	}
 	/* we have several max7315 on the board, we only need load several
 	 * instances of the same pca953x driver to cover them
@@ -48,8 +48,12 @@ static void __init *max7315_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling back to"
+		       "dynamic allocation\n", __func__);
 		return NULL;
+	}
+
 	max7315->gpio_base = gpio_base;
 	if (intr != -1) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +9 -3
index ee22864..4b33aab 100644
@@ -14,15 +14,21 @@
 #include <linux/i2c.h>
 #include <asm/intel-mid.h>
 
+#define MPU3050_INT		"mpu3050_int"
+
 static void *mpu3050_platform_data(void *info)
 {
 	struct i2c_board_info *i2c_info = info;
-	int intr = get_gpio_by_name("mpu3050_int");
+	int intr = get_gpio_by_name(MPU3050_INT);
 
-	if (intr < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       MPU3050_INT);
+		return ERR_PTR(intr);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
+
 	return NULL;
 }
 
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +5 -2
index 429a941..190b2d2 100644
@@ -41,13 +41,16 @@ static void __init *pcal9555a_platform_data(void *info)
 	intr = get_gpio_by_name(intr_pin_name);
 
 	/* Check if the SFI record valid */
-	if (gpio_base = -1)
+	if (gpio_base = -1) {
+		pr_err("%s: Unknown GPIO base number, falling back to dynamic"
+		       "allocation\n", __func__);
 		return NULL;
+	}
 
 	if (nr >= PCAL9555A_NUM) {
 		pr_err("%s: Too many instances, only %d supported\n", __func__,
 		       PCAL9555A_NUM);
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	pcal9555a = &pcal9555a_pdata[nr++];
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +5 -1
index 4f41372..145b03d 100644
@@ -34,8 +34,12 @@ static void *tca6416_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling back to dynamic"
+		       "allocation\n", __func__);
 		return NULL;
+	}
+
 	tca6416.gpio_base = gpio_base;
 	if (intr >= 0) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/sfi.c +17 -4
index 051d264..78ee7eb 100644
@@ -335,9 +335,13 @@ static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry,
 
 	pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
 		pentry->name, pentry->irq);
+
 	pdata = intel_mid_sfi_get_pdata(dev, pentry);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	pdev = platform_device_alloc(pentry->name, 0);
 	if (pdev = NULL) {
@@ -371,8 +375,11 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
 		spi_info.chip_select);
 
 	pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	spi_info.platform_data = pdata;
 	if (dev->delay)
@@ -398,8 +405,11 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
 		i2c_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
 	i2c_info.platform_data = pdata;
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	if (dev->delay)
 		intel_scu_i2c_device_register(pentry->host_num, &i2c_info);
@@ -424,8 +434,11 @@ static void __init sfi_handle_sd_dev(struct sfi_device_table_entry *pentry,
 		 sd_info.max_clk,
 		 sd_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	/* Nothing we can do with this for now */
 	sd_info.platform_data = pdata;
Signature · 1 line
2.7.4
#14 lore raw

Re: [PATCH v2 1/1] intel-mid: Fix sfi get_platform_data() return value issues

Quoted 1 line · Kuppuswamy Sathyanarayanan

According to the intel_mid_sfi_get_pdata() function definition,

"function" is implied, remove the word.

Quoted 1 line

get_platform_data() function

Ditto.

Quoted 1 line

should returns NULL on no platform

returns -> return

Quoted 4 lines

data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

sfi -> SFI

Looking into patch I would consider to split it to series:

1. Rewrite GPIO expander logic to cover dynamic allocation. You have to check how it supposed to be in GPIO framework. IIRC gpio_base = -1 (perhaps a defined constant) will do the trick.
2. Fix the actual return codes (maybe with changes to sfi.c).
3. Fix and add error messages.
4+ (in the future) Address code duplication

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void *info) · line 33

Quoted 12 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
@@ -29,9 +29,9 @@ static void __init *max7315_platform_data(void
 *info)
  	char intr_pin_name[SFI_NAME_LEN + 1];


  if (nr = MAX7315_NUM) {

arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -3
-		pr_err("too many max7315s, we only support %d\n",
-				MAX7315_NUM);
-		return NULL;
+		pr_err("%s: too many max7315s, we only support %d\n",
+		       __func__, MAX7315_NUM);

Use the same as for PCAL9555A:

pr_err("%s: Too many instances, only %d supported\n",

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void *info) · line 53

Quoted 10 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +0 -0
@@ -48,8 +48,12 @@ static void __init *max7315_platform_data(void
 *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);

arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -1
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling back

to"

arch/x86/platform/intel-mid/device_libs/platform_max7315.c +1 -0
+		       "dynamic allocation\n", __func__);

Don't split literals.

pr_err("...long literal...\n",
       args...);

No. This not just the message you show and abort initialization, in case of dynamic allocation you have to proceed initialization.

Quoted 9 lines

index ee22864..4b33aab 100644

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +0 -0
@@ -14,15 +14,21 @@

  i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET; +
  return NULL;

This change doesn't belong to the series.

Quoted 18 lines

 }

(quoted diff) +0 -0

mid/device_libs/platform_pcal9555a.c b/arch/x86/platform/intel- mid/device_libs/platform_pcal9555a.c
index 429a941..190b2d2 100644

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -41,13 +41,16 @@ static void __init *pcal9555a_platform_data(void
 *info)
  	intr = get_gpio_by_name(intr_pin_name);


  /* Check if the SFI record valid */

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +2 -1
-	if (gpio_base = -1)
+	if (gpio_base = -1) {
+		pr_err("%s: Unknown GPIO base number, falling back to

dynamic"

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +1 -0
+		       "allocation\n", __func__);
Quoted 1 line

  return NULL;

Same comment as above for gpio_base.

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c

Quoted 12 lines
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +0 -0
@@ -34,8 +34,12 @@ static void *tca6416_platform_data(void *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +2 -1
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling back to

dynamic"

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +1 -0
+		       "allocation\n", __func__);

Ditto.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#15 lore raw

Re: [PATCH v2 1/1] intel-mid: Fix sfi get_platform_data() return value issues

Thanks for the review Andy. Please check my comments inline.

Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Kuppuswamy Sathyanarayanan

According to the intel_mid_sfi_get_pdata() function definition,

"function" is implied, remove the word.

Will be fixed in next version.

Quoted 3 lines
Quoted 2 lines

get_platform_data() function

Ditto.

Same as above.

Quoted 3 lines
Quoted 2 lines

should returns NULL on no platform

returns -> return

Same as above.

Quoted 6 lines
Quoted 5 lines

data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

sfi -> SFI

Same as above.

Quoted 6 lines

Looking into patch I would consider to split it to series:

1. Rewrite GPIO expander logic to cover dynamic allocation. You have to check how it supposed to be in GPIO framework. IIRC gpio_base = -1

I checked the expander driver logic. As long as we return platform data as NULL, it by default falls back to dynamic allocation. So I think returning NULL on gpio_base = -1 is itself enough to support the dynamic allocation.

file: a/drivers/gpio/gpio-pca953x.c

755 pdata = dev_get_platdata(&client->dev);
756 if (pdata) {

757                 irq_base = pdata->irq_base;
758                 chip->gpio_start = pdata->gpio_base;
759                 invert = pdata->invert;
760                 chip->names = pdata->names;

761 } else {
762 chip->gpio_start = -1;
763 irq_base = 0;
764 }

Quoted 3 lines

(perhaps a defined constant) will do the trick.
2. Fix the actual return codes (maybe with changes to sfi.c).
3. Fix and add error messages.

I can split the patch into two. One for return code fix and another for adding error messages.

Quoted 1 line

4+ (in the future) Address code duplication

Agreed.

Quoted 15 lines

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void · line 34

Quoted 13 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -3
@@ -29,9 +29,9 @@ static void __init *max7315_platform_data(void
 *info)
  	char intr_pin_name[SFI_NAME_LEN + 1];
 
  	if (nr = MAX7315_NUM) {
-		pr_err("too many max7315s, we only support %d\n",
-				MAX7315_NUM);
-		return NULL;
+		pr_err("%s: too many max7315s, we only support %d\n",
+		       __func__, MAX7315_NUM);

Use the same as for PCAL9555A:

Quoted 1 line

pr_err("%s: Too many instances, only %d supported\n",

Will be fixed in next version.

Quoted 13 lines

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void *info) · line 53

Quoted 11 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -1
@@ -48,8 +48,12 @@ static void __init *max7315_platform_data(void
 *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling back

to"

arch/x86/platform/intel-mid/device_libs/platform_max7315.c +1 -0
+		       "dynamic allocation\n", __func__);

Don't split literals.

Quoted 5 lines

pr_err("...long literal...\n",

        args...);

No. This not just the message you show and abort initialization, in case of dynamic allocation you have to proceed initialization.

How about we go with following warning message. Since using dynamic gpio allocation is not an error, I think a warning message is more than enough here. Also , I don't see any value in adding "Unknown gpio base number" to the error message. So we can remove it to fit the log message into one line.

+ if (gpio_base = -1) {
+ pr_warn("%s: falling back to dynamic gpio allocation\n",
+ __func__);

Quoted 10 lines

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c line 17

Quoted 9 lines

index ee22864..4b33aab 100644

arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +1 -0
@@ -14,15 +14,21 @@
 
  	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
+
  	return NULL;

This change doesn't belong to the series.

Submitting a separate patch to fix this this single style issue seems to be over kill. Will it be ok if I add this to my debug message patch ?

Quoted 13 lines
Quoted 13 lines
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +0 -0
  }
 
(quoted diff) +0 -0

mid/device_libs/platform_pcal9555a.c b/arch/x86/platform/intel- mid/device_libs/platform_pcal9555a.c
index 429a941..190b2d2 100644

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -41,13 +41,16 @@ static void __init *pcal9555a_platform_data(void
 *info)
  	intr = get_gpio_by_name(intr_pin_name);
 
Quoted 8 lines

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c

Quoted 7 lines
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +2 -1
  	/* Check if the SFI record valid */
-	if (gpio_base = -1)
+	if (gpio_base = -1) {
+		pr_err("%s: Unknown GPIO base number, falling back to

dynamic"

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +1 -0
+		       "allocation\n", __func__);
  		return NULL;

Same comment as above for gpio_base.

Will be fixed in next version.

Quoted 15 lines

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c

Quoted 12 lines
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +2 -1
@@ -34,8 +34,12 @@ static void *tca6416_platform_data(void *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling back to

dynamic"

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +1 -0
+		       "allocation\n", __func__);

Ditto.

Signature · 2 lines
Sathyanarayanan Kuppuswamy
Android kernel developer
#16 lore raw

Re: [PATCH v2 1/1] intel-mid: Fix sfi get_platform_data() return value issues

Quoted 11 lines · sathyanarayanan kuppuswamy

1. Rewrite GPIO expander logic to cover dynamic allocation. You have

Quoted 2 lines

to
check how it supposed to be in GPIO framework. IIRC gpio_base = -1

I checked the expander driver logic. As long as we return platform data
as NULL, it by default falls back to dynamic allocation. So I think returning NULL on gpio_base = -1 is itself enough to support the dynamic allocation.

file: a/drivers/gpio/gpio-pca953x.c

Quoted 10 lines

755         pdata = dev_get_platdata(&client->dev); 756         if (pdata) {
757                 irq_base = pdata->irq_base; 758                 chip->gpio_start = pdata->gpio_base; 759                 invert = pdata->invert;
760                 chip->names = pdata->names; 761         } else {
762                 chip->gpio_start = -1;
763                 irq_base = 0;
764         }

Yes, but we get 2 parameters: IRQ line (if used) and gpio_base. And I dunno how to proceed if we have gpio_base not set and IRQ line is set.

So, it needs a comment what we will do. Currently it says that "Check if the SFI record valid". So, if it's indeed so, than we can't use even dynamic allocation.

Quoted 20 lines
Quoted 11 lines

arch/x86/platform/intel-mid/device_libs/platform_max7315.c static void __init *max7315_platform_data(void *info) · line 53

Quoted 6 lines
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +2 -1
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_err("%s: Unknown GPIO base number, falling

back
to"

arch/x86/platform/intel-mid/device_libs/platform_max7315.c +1 -0
+		       "dynamic allocation\n", __func__);

No. This not just the message you show and abort initialization, in case
of dynamic allocation you have to proceed initialization.

How about we go with following warning message. Since using dynamic gpio
allocation is not an error, I think a warning message is more than enough here. Also , I don't see any value in adding "Unknown gpio base
number" to the error message. So we can remove it to fit the log message
into one line.

Quoted 4 lines

+       if (gpio_base = -1) {
+               pr_warn("%s: falling back to dynamic gpio allocation\n",
+                       __func__);

See above. Perhaps we need to prevent the device driver initialization.

Quoted 11 lines

--- a/arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c

Quoted 7 lines
Quoted 6 lines

+++ b/arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c

(quoted diff) +0 -0
@@ -14,15 +14,21 @@


   i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET; +
   return NULL;

This change doesn't belong to the series.

Submitting a separate patch to fix this this single style issue seems to
be over kill. Will it be ok if I add this to my debug message patch ?

For me sounds okay, but what I know most of the maintainers doesn't approve such changes ("white space" type of patches are most hateful).

So, I would not do this at all.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#17 lore raw

PATCH v3 1/3 intel-mid: Fix sfi get_platform_data() return value issues

In reply to Kuppuswamy Sathyanarayanan

According to the intel_mid_sfi_get_pdata() definition, get_platform_data() should return NULL on no platform data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various SFI device libs code.

---
 arch/x86/platform/intel-mid/device_libs/platform_lis331.c    | 4 ++--
 arch/x86/platform/intel-mid/device_libs/platform_max7315.c   | 2 +-
 arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c   | 2 +-
 arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -2
index a35cf91..8be5d40 100644
@@ -22,9 +22,9 @@ static void __init *lis331dl_platform_data(void *info)
 	int intr2nd = get_gpio_by_name("accel_2");
 
 	if (intr < 0)
-		return NULL;
+		return ERR_PTR(intr);
 	if (intr2nd < 0)
-		return NULL;
+		ERR_PTR(intr2nd);
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +1 -1
index 6e075af..34dc59d 100644
@@ -31,7 +31,7 @@ static void __init *max7315_platform_data(void *info)
 	if (nr = MAX7315_NUM) {
 		pr_err("too many max7315s, we only support %d\n",
 				MAX7315_NUM);
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 	/* we have several max7315 on the board, we only need load several
 	 * instances of the same pca953x driver to cover them
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +1 -1
index ee22864..f434f88 100644
@@ -20,7 +20,7 @@ static void *mpu3050_platform_data(void *info)
 	int intr = get_gpio_by_name("mpu3050_int");
 
 	if (intr < 0)
-		return NULL;
+		return ERR_PTR(intr);
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	return NULL;
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +1 -1
index 429a941..563f77f 100644
@@ -47,7 +47,7 @@ static void __init *pcal9555a_platform_data(void *info)
 	if (nr >= PCAL9555A_NUM) {
 		pr_err("%s: Too many instances, only %d supported\n", __func__,
 		       PCAL9555A_NUM);
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	pcal9555a = &pcal9555a_pdata[nr++];
Signature · 1 line
2.7.4
#18 lore raw

PATCH v3 2/3 intel-mid: Add valid error messages on init failure

In reply to Kuppuswamy Sathyanarayanan

Added valid error/warning messages to platform data initalization failures in SFI device libs code.

---
 .../intel-mid/device_libs/platform_emc1403.c        | 18 ++++++++++++++----
 .../platform/intel-mid/device_libs/platform_ipc.c   |  5 ++++-
 .../intel-mid/device_libs/platform_lis331.c         | 20 +++++++++++++++-----
 .../intel-mid/device_libs/platform_max7315.c        | 10 +++++++---
 .../intel-mid/device_libs/platform_mpu3050.c        |  9 +++++++--
 .../intel-mid/device_libs/platform_pcal9555a.c      |  5 ++++-
 .../intel-mid/device_libs/platform_tca6416.c        |  6 +++++-
 arch/x86/platform/intel-mid/sfi.c                   | 21 +++++++++++++++++----
 8 files changed, 73 insertions(+), 21 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +14 -4
index c259fb6..bd776b04 100644
@@ -15,17 +15,27 @@
 #include <linux/i2c.h>
 #include <asm/intel-mid.h>
 
+#define EMC1403_THERMAL_INT		"thermal_int"
+#define EMC1403_THERMAL_ALERT_INT	"thermal_alert"
+
 static void __init *emc1403_platform_data(void *info)
 {
 	static short intr2nd_pdata;
 	struct i2c_board_info *i2c_info = info;
-	int intr = get_gpio_by_name("thermal_int");
-	int intr2nd = get_gpio_by_name("thermal_alert");
+	int intr = get_gpio_by_name(EMC1403_THERMAL_INT);
+	int intr2nd = get_gpio_by_name(EMC1403_THERMAL_ALERT_INT);
 
-	if (intr < 0)
+	if (intr < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       EMC1403_THERMAL_INT);
 		return NULL;
-	if (intr2nd < 0)
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       EMC1403_THERMAL_ALERT_INT);
 		return NULL;
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_ipc.c +4 -1
index a84b73d..6704694 100644
@@ -42,8 +42,11 @@ void __init ipc_device_handler(struct sfi_device_table_entry *pentry,
 	 * On Medfield the platform device creation is handled by the MSIC
 	 * MFD driver so we don't need to do it here.
 	 */
-	if (intel_mid_has_msic())
+	if (intel_mid_has_msic()) {
+		pr_err("%s: device %s will be handled by MSIC mfd driver\n",
+		       __func__, pentry->name);
 		return;
+	}
 
 	pdev = platform_device_alloc(pentry->name, 0);
 	if (pdev = NULL) {
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +15 -5
index 8be5d40..393c23e 100644
@@ -14,17 +14,27 @@
 #include <linux/gpio.h>
 #include <asm/intel-mid.h>
 
+#define LIS331DL_ACCEL_INT1	"accel_int"
+#define LIS331DL_ACCEL_INT2	"accel_2"
+
 static void __init *lis331dl_platform_data(void *info)
 {
 	static short intr2nd_pdata;
 	struct i2c_board_info *i2c_info = info;
-	int intr = get_gpio_by_name("accel_int");
-	int intr2nd = get_gpio_by_name("accel_2");
+	int intr = get_gpio_by_name(LIS331DL_ACCEL_INT1);
+	int intr2nd = get_gpio_by_name(LIS331DL_ACCEL_INT2);
 
-	if (intr < 0)
+	if (intr < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       LIS331DL_ACCEL_INT1);
 		return ERR_PTR(intr);
-	if (intr2nd < 0)
-		ERR_PTR(intr2nd);
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       LIS331DL_ACCEL_INT2);
+		return ERR_PTR(intr2nd);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +7 -3
index 34dc59d..8989f81 100644
@@ -29,8 +29,8 @@ static void __init *max7315_platform_data(void *info)
 	char intr_pin_name[SFI_NAME_LEN + 1];
 
 	if (nr = MAX7315_NUM) {
-		pr_err("too many max7315s, we only support %d\n",
-				MAX7315_NUM);
+		pr_err("%s: Too many instances, only %d supported\n", __func__,
+		       MAX7315_NUM);
 		return ERR_PTR(-ENOMEM);
 	}
 	/* we have several max7315 on the board, we only need load several
@@ -48,8 +48,12 @@ static void __init *max7315_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_warn("%s: falling back to dynamic gpio allocation\n",
+			__func__);
 		return NULL;
+	}
+
 	max7315->gpio_base = gpio_base;
 	if (intr != -1) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +7 -2
index f434f88..c79c87f 100644
@@ -14,13 +14,18 @@
 #include <linux/i2c.h>
 #include <asm/intel-mid.h>
 
+#define MPU3050_INT		"mpu3050_int"
+
 static void *mpu3050_platform_data(void *info)
 {
 	struct i2c_board_info *i2c_info = info;
-	int intr = get_gpio_by_name("mpu3050_int");
+	int intr = get_gpio_by_name(MPU3050_INT);
 
-	if (intr < 0)
+	if (intr < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n", __func__,
+		       MPU3050_INT);
 		return ERR_PTR(intr);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	return NULL;
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +4 -1
index 563f77f..cde764e 100644
@@ -41,8 +41,11 @@ static void __init *pcal9555a_platform_data(void *info)
 	intr = get_gpio_by_name(intr_pin_name);
 
 	/* Check if the SFI record valid */
-	if (gpio_base = -1)
+	if (gpio_base = -1) {
+		pr_warn("%s: falling back to dynamic gpio allocation\n",
+			__func__);
 		return NULL;
+	}
 
 	if (nr >= PCAL9555A_NUM) {
 		pr_err("%s: Too many instances, only %d supported\n", __func__,
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +5 -1
index 4f41372..4d4393e 100644
@@ -34,8 +34,12 @@ static void *tca6416_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_warn("%s: falling back to dynamic gpio allocation\n",
+			__func__);
 		return NULL;
+	}
+
 	tca6416.gpio_base = gpio_base;
 	if (intr >= 0) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/sfi.c +17 -4
index 051d264..78ee7eb 100644
@@ -335,9 +335,13 @@ static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry,
 
 	pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
 		pentry->name, pentry->irq);
+
 	pdata = intel_mid_sfi_get_pdata(dev, pentry);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	pdev = platform_device_alloc(pentry->name, 0);
 	if (pdev = NULL) {
@@ -371,8 +375,11 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
 		spi_info.chip_select);
 
 	pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	spi_info.platform_data = pdata;
 	if (dev->delay)
@@ -398,8 +405,11 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
 		i2c_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
 	i2c_info.platform_data = pdata;
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	if (dev->delay)
 		intel_scu_i2c_device_register(pentry->host_num, &i2c_info);
@@ -424,8 +434,11 @@ static void __init sfi_handle_sd_dev(struct sfi_device_table_entry *pentry,
 		 sd_info.max_clk,
 		 sd_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_debug("%s:  Can't get platform data for %s\n", __func__,
+			 pentry->name);
 		return;
+	}
 
 	/* Nothing we can do with this for now */
 	sd_info.platform_data = pdata;
Signature · 1 line
2.7.4
#19 lore raw

Re: [PATCH v3 2/3] intel-mid: Add valid error messages on init failure

Quoted 2 lines · Kuppuswamy Sathyanarayanan

Added valid error/warning messages to platform data initalization failures in SFI device libs code.

Looks good to me after addressing the following comments.

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c line 19

Quoted 13 lines

(quoted diff) +0 -0

mid/device_libs/platform_emc1403.c b/arch/x86/platform/intel- mid/device_libs/platform_emc1403.c
index c259fb6..bd776b04 100644

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +0 -0
@@ -15,17 +15,27 @@
  #include <linux/i2c.h>
  #include <asm/intel-mid.h>

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +2 -0
+#define EMC1403_THERMAL_INT		"thermal_int"
+#define EMC1403_THERMAL_ALERT_INT	"thermal_alert"

I would be cosistent, i.e.
EMC1403_INT1  "..."
EMC1403_INT2  "..."

Quoted 15 lines

+
 static void __init *emc1403_platform_data(void *info) {
  static short intr2nd_pdata;
  struct i2c_board_info *i2c_info = info;

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +2 -2
-	int intr = get_gpio_by_name("thermal_int");
-	int intr2nd = get_gpio_by_name("thermal_alert");
+	int intr = get_gpio_by_name(EMC1403_THERMAL_INT);
+	int intr2nd = get_gpio_by_name(EMC1403_THERMAL_ALERT_INT);

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +2 -1
-	if (intr < 0)
+	if (intr < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n",

__func__,

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +1 -0
+		       EMC1403_THERMAL_INT);
Quoted 1 line

  return NULL;

Souldn't we return an error here?

Quoted 8 lines
arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +4 -1
-	if (intr2nd < 0)
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: Can't find %s GPIO interrupt\n",

__func__,

arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +1 -0
+		       EMC1403_THERMAL_ALERT_INT);

  return NULL;

Ditto.

Would you check _all_ files under device libs?

Quoted 18 lines
arch/x86/platform/intel-mid/device_libs/platform_emc1403.c +1 -0
+	}


  i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET; intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;

arch/x86/platform/intel-mid/device_libs/platform_ipc.c +0 -0
index a84b73d..6704694 100644
@@ -42,8 +42,11 @@ void __init ipc_device_handler(struct
 sfi_device_table_entry *pentry,
  	 * On Medfield the platform device creation is handled by the

MSIC
   * MFD driver so we don't need to do it here. */

arch/x86/platform/intel-mid/device_libs/platform_ipc.c +2 -1
-	if (intel_mid_has_msic())
+	if (intel_mid_has_msic()) {
+		pr_err("%s: device %s will be handled by MSIC mfd
Quoted 1 line

driver\n",

Remove "mfd" word.

Quoted 15 lines
arch/x86/platform/intel-mid/device_libs/platform_ipc.c +1 -0
+		       __func__, pentry->name);

  return;

arch/x86/platform/intel-mid/device_libs/platform_ipc.c +1 -0
+	}


  pdev = platform_device_alloc(pentry->name, 0); if (pdev = NULL) {

arch/x86/platform/intel-mid/device_libs/platform_lis331.c +0 -0
index 8be5d40..393c23e 100644
@@ -14,17 +14,27 @@
  #include <linux/gpio.h>
  #include <asm/intel-mid.h>

arch/x86/platform/intel-mid/device_libs/platform_lis331.c line 18

Quoted 2 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -0
+#define LIS331DL_ACCEL_INT1	"accel_int"
+#define LIS331DL_ACCEL_INT2	"accel_2"

LIS331DL_INT1
LIS331DL_INT2

Quoted 11 lines
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +0 -0
@@ -48,8 +48,12 @@ static void __init *max7315_platform_data(void
 *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);

arch/x86/platform/intel-mid/device_libs/platform_lis331.c +2 -1
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_warn("%s: falling back to dynamic gpio

allocation\n",

arch/x86/platform/intel-mid/device_libs/platform_lis331.c +1 -0
+			__func__);

  return NULL;

Depends on my comment to the previous series.

Quoted 7 lines
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +0 -0
@@ -14,13 +14,18 @@
  #include <linux/i2c.h>
  #include <asm/intel-mid.h>


+#define MPU3050_INT "mpu3050_int"

MPU3050_INT1

Quoted 15 lines

mid/device_libs/platform_pcal9555a.c b/arch/x86/platform/intel- mid/device_libs/platform_pcal9555a.c
index 563f77f..cde764e 100644

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -41,8 +41,11 @@ static void __init *pcal9555a_platform_data(void
 *info)
  	intr = get_gpio_by_name(intr_pin_name);


  /* Check if the SFI record valid */

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +2 -1
-	if (gpio_base = -1)
+	if (gpio_base = -1) {
+		pr_warn("%s: falling back to dynamic gpio

allocation\n",

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +1 -0
+			__func__);
Quoted 1 line

  return NULL;

Same as above

Quoted 14 lines

mid/device_libs/platform_tca6416.c b/arch/x86/platform/intel- mid/device_libs/platform_tca6416.c
index 4f41372..4d4393e 100644

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +0 -0
@@ -34,8 +34,12 @@ static void *tca6416_platform_data(void *info)
  	gpio_base = get_gpio_by_name(base_pin_name);
  	intr = get_gpio_by_name(intr_pin_name);

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +2 -1
-	if (gpio_base < 0)
+	if (gpio_base < 0) {
+		pr_warn("%s: falling back to dynamic gpio

allocation\n",

arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +1 -0
+			__func__);
Quoted 1 line

  return NULL;

Same as above

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#20 lore raw

PATCH v3 3/3 intel-mid: Move boundry check to the start of init code

In reply to Kuppuswamy Sathyanarayanan

Moved the instance boundary check to the start of the pcal9555a platform init code. This will prevent unnecessary initialization on instance boundary error.

---
 arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +6 -6
index cde764e..4e5dd95 100644
@@ -34,6 +34,12 @@ static void __init *pcal9555a_platform_data(void *info)
 	char intr_pin_name[SFI_NAME_LEN + 1];
 	int gpio_base, intr;
 
+	if (nr >= PCAL9555A_NUM) {
+		pr_err("%s: Too many instances, only %d supported\n", __func__,
+		       PCAL9555A_NUM);
+		return ERR_PTR(-ENOMEM);
+	}
+
 	snprintf(base_pin_name, sizeof(base_pin_name), "%s_base", type);
 	snprintf(intr_pin_name, sizeof(intr_pin_name), "%s_int", type);
 
@@ -47,12 +53,6 @@ static void __init *pcal9555a_platform_data(void *info)
 		return NULL;
 	}
 
-	if (nr >= PCAL9555A_NUM) {
-		pr_err("%s: Too many instances, only %d supported\n", __func__,
-		       PCAL9555A_NUM);
-		return ERR_PTR(-ENOMEM);
-	}
-
 	pcal9555a = &pcal9555a_pdata[nr++];
 	pcal9555a->gpio_base = gpio_base;
 
Signature · 1 line
2.7.4
#21 lore raw

Re: [PATCH v3 3/3] intel-mid: Move boundry check to the start of init code

Quoted 3 lines · Kuppuswamy Sathyanarayanan

Moved the instance boundary check to the start of the pcal9555a platform init code. This will prevent unnecessary initialization on instance boundary error.

I don't see how it makes any better.

I would drop this patch.

Quoted 46 lines

linux.intel.com>
---
 arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c | 12
++++++------

 1 file changed, 6 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

mid/device_libs/platform_pcal9555a.c b/arch/x86/platform/intel- mid/device_libs/platform_pcal9555a.c
index cde764e..4e5dd95 100644

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -34,6 +34,12 @@ static void __init *pcal9555a_platform_data(void
 *info)
  	char intr_pin_name[SFI_NAME_LEN + 1];
  	int gpio_base, intr;

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +2 -0
+	if (nr >= PCAL9555A_NUM) {
+		pr_err("%s: Too many instances, only %d supported\n",

__func__,

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +4 -0
+		       PCAL9555A_NUM);
+		return ERR_PTR(-ENOMEM);
+	}
+

  snprintf(base_pin_name, sizeof(base_pin_name), "%s_base", type);
  snprintf(intr_pin_name, sizeof(intr_pin_name), "%s_int", type);

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -0
@@ -47,12 +53,6 @@ static void __init *pcal9555a_platform_data(void
 *info)
  		return NULL;
  	}

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -2
-	if (nr >= PCAL9555A_NUM) {
-		pr_err("%s: Too many instances, only %d supported\n",

__func__,

arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +0 -4
-		       PCAL9555A_NUM);
-		return ERR_PTR(-ENOMEM);
-	}
-

  pcal9555a = &pcal9555a_pdata[nr++];
  pcal9555a->gpio_base = gpio_base;

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#22 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Sathyanarayanan Kuppuswamy

IMO, Main problem here is, In some scenarios get_platform_data returns
NULL on error case and in some cases it return NULL for no platform data
case.

We have possibility of the following scenarios:
1) fatal error (should return error code and fail booting)
2) non-fatal error (prevents certain device to be enumerated, pdata NULL)
3) no pdata for the device (not an error! pdata is optional to the certain driver)
4) pdata != NULL (fully armed device driver)

According to above I doubt we will have many 1) cases. Otherwise pdata NULL is okay.

Quoted 4 lines

For example, in following function, returning NULL on gpio_base = -1 and when nr >= PCAL9555A_NUM is incorrect. I think in both these scenarios valid behavior is to stop the device creation process.

Yes, but do _not_ stop processing and booting!

Quoted 6 lines

Creating an i2c device without validi irq number or gpio number is incorrect.

So after investigating it bit more, I think its more appropriate to fix
these error cases in device_libs dir. Let me know your comments.

I doubt that is a proper fix. It might be part of the fix in sfi.c where you somehow distinguish fatal errors from non-fatal.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#23 lore raw
In reply to Dan Carpenter

Hi Andy,

Quoted 15 lines · Andy Shevchenko
Quoted 5 lines · Sathyanarayanan Kuppuswamy

IMO, Main problem here is, In some scenarios get_platform_data returns
NULL on error case and in some cases it return NULL for no platform data
case.

We have possibility of the following scenarios:
1) fatal error (should return error code and fail booting)
2) non-fatal error (prevents certain device to be enumerated, pdata = NULL)
3) no pdata for the device (not an error! pdata is optional to the certain driver)
4) pdata != NULL (fully armed device driver)

Quoted 2 lines

According to above I doubt we will have many 1) cases. Otherwise pdata = NULL is okay.

I agree with 2,3 and 4 scenarios. But I am not sure about the first case. Since these are peripheral devices, any failure in them should not stop the device boot. Do you have any examples for this case ?

Attached patch fixes the return value issues in get_platform_data code in device_libs directory. Please check and let me know your comments.

Quoted 16 lines
Quoted 4 lines

For example, in following function, returning NULL on gpio_base == -1 and when nr >= PCAL9555A_NUM is incorrect. I think in both these scenarios valid behavior is to stop the device creation process.

Yes, but do _not_ stop processing and booting!

Quoted 6 lines

Creating an i2c device without validi irq number or gpio number is incorrect.

So after investigating it bit more, I think its more appropriate to fix
these error cases in device_libs dir. Let me know your comments.

I doubt that is a proper fix. It might be part of the fix in sfi.c where you somehow distinguish fatal errors from non-fatal.

Signature · 2 lines
Sathyanarayanan Kuppuswamy
Android kernel developer

From c534b068dbfe26abd0a730f2c61695fbccd6964a Mon Sep 17 00:00:00 2001
From: Kuppuswamy Sathyanarayanan <[email protected]>
Date: Tue, 6 Sep 2016 16:42:15 -0700
Subject: [PATCH 1/1] intel-mid: Fix sfi get_platform_data() return value
issues

According to the intel_mid_sfi_get_pdata() function definition, get_platform_data() function should returns NULL on no platform data scenario and return ERR_PTR on platform data initialization failures. But current device platform initialization code does not follow this requirement. This patch fixes the return values issues in various sfi device libs code.

---
 .../platform/intel-mid/device_libs/platform_lis331.c    | 13 +++++++++----
 .../platform/intel-mid/device_libs/platform_max7315.c   |  9 ++++++---
 .../platform/intel-mid/device_libs/platform_mpu3050.c   |  7 +++++--
 .../platform/intel-mid/device_libs/platform_pcal9555a.c |  8 +++++---
 .../platform/intel-mid/device_libs/platform_tca6416.c   |  7 +++++--
 arch/x86/platform/intel-mid/sfi.c                       | 17 +++++++++++++----
 6 files changed, 43 insertions(+), 18 deletions(-)
arch/x86/platform/intel-mid/device_libs/platform_lis331.c +9 -4
index a35cf91..2fd200b 100644
@@ -21,10 +21,15 @@ static void __init *lis331dl_platform_data(void *info)
 	int intr = get_gpio_by_name("accel_int");
 	int intr2nd = get_gpio_by_name("accel_2");
 
-	if (intr < 0)
-		return NULL;
-	if (intr2nd < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt1 error\n", __func__);
+		return ERR_PTR(intr);
+	}
+
+	if (intr2nd < 0) {
+		pr_err("%s: invalid interrupt2 error\n", __func__);
+		return ERR_PTR(intr2nd);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
 	intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_max7315.c +6 -3
index 6e075af..cc20dfc 100644
@@ -31,7 +31,7 @@ static void __init *max7315_platform_data(void *info)
 	if (nr == MAX7315_NUM) {
 		pr_err("too many max7315s, we only support %d\n",
 				MAX7315_NUM);
-		return NULL;
+		return ERR_PTR(-ENODEV);
 	}
 	/* we have several max7315 on the board, we only need load several
 	 * instances of the same pca953x driver to cover them
@@ -48,8 +48,11 @@ static void __init *max7315_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);
+	}
+
 	max7315->gpio_base = gpio_base;
 	if (intr != -1) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/device_libs/platform_mpu3050.c +5 -2
index ee22864..2008824 100644
@@ -19,10 +19,13 @@ static void *mpu3050_platform_data(void *info)
 	struct i2c_board_info *i2c_info = info;
 	int intr = get_gpio_by_name("mpu3050_int");
 
-	if (intr < 0)
-		return NULL;
+	if (intr < 0) {
+		pr_err("%s: invalid interrupt error\n", __func__);
+		return ERR_PTR(intr);
+	}
 
 	i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
+
 	return NULL;
 }
 
arch/x86/platform/intel-mid/device_libs/platform_pcal9555a.c +5 -3
index 429a941..97e92a2 100644
@@ -41,13 +41,15 @@ static void __init *pcal9555a_platform_data(void *info)
 	intr = get_gpio_by_name(intr_pin_name);
 
 	/* Check if the SFI record valid */
-	if (gpio_base == -1)
-		return NULL;
+	if (gpio_base == -1) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);
+	}
 
 	if (nr >= PCAL9555A_NUM) {
 		pr_err("%s: Too many instances, only %d supported\n", __func__,
 		       PCAL9555A_NUM);
-		return NULL;
+		return ERR_PTR(-ENODEV);
 	}
 
 	pcal9555a = &pcal9555a_pdata[nr++];
arch/x86/platform/intel-mid/device_libs/platform_tca6416.c +5 -2
index 4f41372..2796956 100644
@@ -34,8 +34,11 @@ static void *tca6416_platform_data(void *info)
 	gpio_base = get_gpio_by_name(base_pin_name);
 	intr = get_gpio_by_name(intr_pin_name);
 
-	if (gpio_base < 0)
-		return NULL;
+	if (gpio_base < 0) {
+		pr_err("%s: invalid gpio base error\n", __func__);
+		return ERR_PTR(gpio_base);
+	}
+
 	tca6416.gpio_base = gpio_base;
 	if (intr >= 0) {
 		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
arch/x86/platform/intel-mid/sfi.c +13 -4
index 051d264..8e7361f 100644
@@ -335,9 +335,12 @@ static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry,
 
 	pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
 		pentry->name, pentry->irq);
+
 	pdata = intel_mid_sfi_get_pdata(dev, pentry);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("ipc_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	pdev = platform_device_alloc(pentry->name, 0);
 	if (pdev == NULL) {
@@ -371,8 +374,10 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
 		spi_info.chip_select);
 
 	pdata = intel_mid_sfi_get_pdata(dev, &spi_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("spi_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	spi_info.platform_data = pdata;
 	if (dev->delay)
@@ -398,8 +403,10 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
 		i2c_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &i2c_info);
 	i2c_info.platform_data = pdata;
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("i2c_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	if (dev->delay)
 		intel_scu_i2c_device_register(pentry->host_num, &i2c_info);
@@ -424,8 +431,10 @@ static void __init sfi_handle_sd_dev(struct sfi_device_table_entry *pentry,
 		 sd_info.max_clk,
 		 sd_info.addr);
 	pdata = intel_mid_sfi_get_pdata(dev, &sd_info);
-	if (IS_ERR(pdata))
+	if (IS_ERR(pdata)) {
+		pr_err("sd_device: %s: invalid platform data\n", pentry->name);
 		return;
+	}
 
 	/* Nothing we can do with this for now */
 	sd_info.platform_data = pdata;
Signature · 1 line
2.7.4
#24 lore raw
In reply to Dan Carpenter
Quoted 14 lines · Sathyanarayanan Kuppuswamy
Quoted 13 lines · Andy Shevchenko

On Tue, 2016-08-30 at 11:18 -0700, Sathyanarayanan Kuppuswamy wrote:
IMO, Main problem here is, In some scenarios get_platform_data

Quoted 2 lines

returns NULL on error case and in some cases it return NULL for no platform data case.

We have possibility of the following scenarios:
1) fatal error (should return error code and fail booting)
2) non-fatal error (prevents certain device to be enumerated, pdata = NULL)
3) no pdata for the device (not an error! pdata is optional to the certain driver)
4) pdata != NULL (fully armed device driver)

Quoted 6 lines
Quoted 2 lines

According to above I doubt we will have many 1) cases. Otherwise pdata = NULL is okay.

I agree with 2,3 and 4 scenarios. But I am not sure about the first case. Since these are peripheral devices, any failure in them should not stop the device boot. Do you have any examples for this case ?

That's what I'm wondering of. I didn't investigate this deep.

In any case for 2) we have to print out a warning (?) message.

Quoted 3 lines

Attached patch fixes the return value issues in get_platform_data code
in device_libs directory. Please check and let me know your comments.

Will do.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy