[patch] of: check for IS_ERR()

2010-02-26 Thread Dan Carpenter
get_phy_device() can return an ERR_PTR()

Signed-off-by: Dan Carpenter erro...@gmail.com
---
I don't have a cross compile environment set up so I can't even compile 
test this.  :/  But err.h is included so it should be OK.

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 18ecae4..b474833 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -69,7 +69,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct 
device_node *np)
}
 
phy = get_phy_device(mdio, be32_to_cpup(addr));
-   if (!phy) {
+   if (!phy || IS_ERR(phy)) {
dev_err(mdio-dev, error probing PHY at address %i\n,
*addr);
continue;
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [patch] of: check for IS_ERR()

2010-03-29 Thread Dan Carpenter
On Fri, Feb 26, 2010 at 01:54:20AM -0800, David Miller wrote:
 From: Dan Carpenter erro...@gmail.com
 Date: Fri, 26 Feb 2010 12:49:41 +0300
 
  get_phy_device() can return an ERR_PTR()
  
  Signed-off-by: Dan Carpenter erro...@gmail.com
  ---
  I don't have a cross compile environment set up so I can't even compile 
  test this.  :/  But err.h is included so it should be OK.
 
 It should return ERR_PTR() consistently.  Checking for both
 NULL and ERR_PTR() is undesirable.

Hi Giulio,

get_phy_device() currently returns NULL because of: 3ee82383f0098a2 phy: 
fix phy address bug.  If I change it to return ERR_PTR(-ENODEV) that
will mean we break out of the loop with an error in mdiobus_register()
where before we would just continue on.

drivers/net/phy/mdio_bus.c
   119  phydev = mdiobus_scan(bus, i);
   120  if (IS_ERR(phydev)) {
   121  err = PTR_ERR(phydev);
   122  goto error;
   123  }

Is that OK?

I'm not really familiar with this hardware at all, I'm just going based
on static analysis. :/

regards,
dan carpenter
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch v2] nouveau: unwind on load errors

2010-07-30 Thread Dan Carpenter
nuveau_load() just returned directly if there was an error instead of   

releasing resources.
 

Signed-off-by: Dan Carpenter erro...@gmail.com
---
V2: updated to the nouveau git tree.

diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c 
b/drivers/gpu/drm/nouveau/nouveau_state.c
index ee3729e..cf16bfb 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -739,8 +739,10 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
int ret;
 
dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
-   if (!dev_priv)
-   return -ENOMEM;
+   if (!dev_priv) {
+   ret = -ENOMEM;
+   goto err_out;
+   }
dev-dev_private = dev_priv;
dev_priv-dev = dev;
 
@@ -750,8 +752,10 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
 dev-pci_vendor, dev-pci_device, dev-pdev-class);
 
dev_priv-wq = create_workqueue(nouveau);
-   if (!dev_priv-wq)
-   return -EINVAL;
+   if (!dev_priv-wq) {
+   ret = -EINVAL;
+   goto err_priv;
+   }
 
/* resource 0 is mmio regs */
/* resource 1 is linear FB */
@@ -764,7 +768,8 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
if (!dev_priv-mmio) {
NV_ERROR(dev, Unable to initialize the mmio mapping. 
 Please report your setup to  DRIVER_EMAIL \n);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto err_wq;
}
NV_DEBUG(dev, regs mapped ok at 0x%llx\n,
(unsigned long long)mmio_start_offs);
@@ -812,7 +817,8 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
break;
default:
NV_INFO(dev, Unsupported chipset 0x%08x\n, reg0);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto err_mmio;
}
 
NV_INFO(dev, Detected an NV%2x generation card (0x%08x)\n,
@@ -820,7 +826,7 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
 
ret = nouveau_remove_conflicting_drivers(dev);
if (ret)
-   return ret;
+   goto err_mmio;
 
/* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */
if (dev_priv-card_type = NV_40) {
@@ -834,7 +840,8 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
dev_priv-ramin_size);
if (!dev_priv-ramin) {
NV_ERROR(dev, Failed to PRAMIN BAR);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto err_mmio;
}
} else {
dev_priv-ramin_size = 1 * 1024 * 1024;
@@ -842,7 +849,8 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
  dev_priv-ramin_size);
if (!dev_priv-ramin) {
NV_ERROR(dev, Failed to map BAR0 PRAMIN.\n);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto err_mmio;
}
}
 
@@ -857,9 +865,21 @@ int nouveau_load(struct drm_device *dev, unsigned long 
flags)
/* For kernel modesetting, init card now and bring up fbcon */
ret = nouveau_card_init(dev);
if (ret)
-   return ret;
+   goto err_ramin;
 
return 0;
+
+err_ramin:
+   iounmap(dev_priv-ramin);
+err_mmio:
+   iounmap(dev_priv-mmio);
+err_wq:
+   destroy_workqueue(dev_priv-wq);
+err_priv:
+   kfree(dev_priv);
+   dev-dev_private = NULL;
+err_out:
+   return ret;
 }
 
 void nouveau_lastclose(struct drm_device *dev)
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] ehci-ppc-of: problems in unwind

2010-08-14 Thread Dan Carpenter
The iounmap(ehci-ohci_hcctrl_reg); should be the first thing we do
because the ioremap() was the last thing we did.  Also if we hit any of
the goto statements in the original code then it would have led to a
NULL dereference of ehci.  This bug was introduced in: 796bcae7361c
USB: powerpc: Workaround for the PPC440EPX USBH_23 errata [take 3]

I modified the few lines in front a little so that my code didn't
obscure the return success code path.

Signed-off-by: Dan Carpenter erro...@gmail.com
---
I don't have a cross compile environment set up so I haven't compiled
this code.  Sorry for that.

diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 335ee69..ba52be4 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -192,17 +192,19 @@ ehci_hcd_ppc_of_probe(struct platform_device *op, const 
struct of_device_id *mat
}
 
rv = usb_add_hcd(hcd, irq, 0);
-   if (rv == 0)
-   return 0;
+   if (rv)
+   goto err_ehci;
+
+   return 0;
 
+err_ehci:
+   if (ehci-has_amcc_usb23)
+   iounmap(ehci-ohci_hcctrl_reg);
iounmap(hcd-regs);
 err_ioremap:
irq_dispose_mapping(irq);
 err_irq:
release_mem_region(hcd-rsrc_start, hcd-rsrc_len);
-
-   if (ehci-has_amcc_usb23)
-   iounmap(ehci-ohci_hcctrl_reg);
 err_rmr:
usb_put_hcd(hcd);
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] qla2xxx: locking problem in qla2x00_init_rings()

2010-09-12 Thread Dan Carpenter
IRQs are already disabled here so we don't need to disable them again.
But more importantly, the spin_lock_irqsave() overwrites flags and
that breaks things when we want to re-enable the IRQs when we call
spin_unlock_irqrestore(ha-hardware_lock, flags);

Signed-off-by: Dan Carpenter erro...@gmail.com
---
This seems like an important bug.  I don't have this hardware but could
someone from QLogic test this out and maybe queue it up for 2.6.36?

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 9c383ba..9f4ba28 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1787,14 +1787,14 @@ qla2x00_init_rings(scsi_qla_host_t *vha)
qla2x00_init_response_q_entries(rsp);
}
 
-   spin_lock_irqsave(ha-vport_slock, flags);
+   spin_lock(ha-vport_slock);
/* Clear RSCN queue. */
list_for_each_entry(vp, ha-vp_list, list) {
vp-rscn_in_ptr = 0;
vp-rscn_out_ptr = 0;
}
 
-   spin_unlock_irqrestore(ha-vport_slock, flags);
+   spin_unlock(ha-vport_slock);
 
ha-isp_ops-config_rings(vha);
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] sata_mv: silence an uninitialized variable warning

2012-03-27 Thread Dan Carpenter
Gcc version 4.6.2-12 complains that if we can't find the nr-ports
property in of_property_read_u32_array() then n_ports is used
uninitialized.  Let's set it to zero in that case.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index ebd0d24..3d8d5c6 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -4026,7 +4026,8 @@ static int mv_platform_probe(struct platform_device *pdev)
struct ata_host *host;
struct mv_host_priv *hpriv;
struct resource *res;
-   int n_ports, rc;
+   int n_ports = 0;
+   int rc;
 
ata_print_version_once(pdev-dev, DRV_VERSION);
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] max17042_battery: fix a couple buffer overflows

2012-03-27 Thread Dan Carpenter
There are a couple issues here caused by confusion between sizeof()
and ARRAY_SIZE().  table_size should be the number of elements, but we
should allocate it with kcalloc() so that we allocate the correct number
of bytes.

In max17042_init_model() we don't allocate enough space so we go past
the end of the array in max17042_read_model_data() and
max17042_model_data_compare().

In max17042_verify_model_lock() we allocate the right amount of space
but we call max17042_read_model_data() with the wrong number of elements
and also in the for loop we go past the end of the array.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com
---
I don't have this hardware.  The original code is clearly buggy, but I
can't test that my fix is correct.  Please review carefully.

diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index e36763a..f8cd48c 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -328,11 +328,10 @@ static inline int max17042_model_data_compare(struct 
max17042_chip *chip,
 static int max17042_init_model(struct max17042_chip *chip)
 {
int ret;
-   int table_size =
-   sizeof(chip-pdata-config_data-cell_char_tbl)/sizeof(u16);
+   int table_size = ARRAY_SIZE(chip-pdata-config_data-cell_char_tbl);
u16 *temp_data;
 
-   temp_data = kzalloc(table_size, GFP_KERNEL);
+   temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
if (!temp_data)
return -ENOMEM;
 
@@ -357,12 +356,11 @@ static int max17042_init_model(struct max17042_chip *chip)
 static int max17042_verify_model_lock(struct max17042_chip *chip)
 {
int i;
-   int table_size =
-   sizeof(chip-pdata-config_data-cell_char_tbl);
+   int table_size = ARRAY_SIZE(chip-pdata-config_data-cell_char_tbl);
u16 *temp_data;
int ret = 0;
 
-   temp_data = kzalloc(table_size, GFP_KERNEL);
+   temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
if (!temp_data)
return -ENOMEM;
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH V1 1/2] staging: iio: add driver for isl29028

2012-04-11 Thread Dan Carpenter
On Wed, Apr 11, 2012 at 10:58:03PM +0530, Laxman Dewangan wrote:
 Intersil's ISL29028 is concurrent Ambient Light and
 Proximity Sensor device.
 Add driver to access the light and IR intensity and
 proximity value via iio interface.
 
 Signed-off-by: Laxman Dewangan ldewan...@nvidia.com
 ---
  drivers/staging/iio/light/Kconfig|   10 +
  drivers/staging/iio/light/Makefile   |1 +
  drivers/staging/iio/light/isl29028.c |  538 
 ++
  3 files changed, 549 insertions(+), 0 deletions(-)
  create mode 100644 drivers/staging/iio/light/isl29028.c
 
 diff --git a/drivers/staging/iio/light/Kconfig 
 b/drivers/staging/iio/light/Kconfig
 index e7e9159..53b49f7 100644
 --- a/drivers/staging/iio/light/Kconfig
 +++ b/drivers/staging/iio/light/Kconfig
 @@ -14,6 +14,16 @@ config SENSORS_ISL29018
   in lux, proximity infrared sensing and normal infrared sensing.
   Data from sensor is accessible via sysfs.
  
 +config SENSORS_ISL29028
 + tristate Intersil ISL29028 Concurrent Light and Proximity Sensor
 + depends on I2C
 + select REGMAP_I2C
 + help
 +  Provides driver for the Intersil's ISL29028 device.
 +  This driver supports the sysfs interface to get the ALS, IR intensity,
 +  Proximity value via iio. The ISL29028 provides the concurrent sensing
 +  of ambient light and proximity.
 +
  config SENSORS_TSL2563
   tristate TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light 
 sensors
   depends on I2C
 diff --git a/drivers/staging/iio/light/Makefile 
 b/drivers/staging/iio/light/Makefile
 index 3011fbf..535d313 100644
 --- a/drivers/staging/iio/light/Makefile
 +++ b/drivers/staging/iio/light/Makefile
 @@ -4,4 +4,5 @@
  
  obj-$(CONFIG_SENSORS_TSL2563)+= tsl2563.o
  obj-$(CONFIG_SENSORS_ISL29018)   += isl29018.o
 +obj-$(CONFIG_SENSORS_ISL29028)   += isl29028.o
  obj-$(CONFIG_TSL2583)+= tsl2583.o
 diff --git a/drivers/staging/iio/light/isl29028.c 
 b/drivers/staging/iio/light/isl29028.c
 new file mode 100644
 index 000..ccd1f7c
 --- /dev/null
 +++ b/drivers/staging/iio/light/isl29028.c
 @@ -0,0 +1,538 @@
 +/*
 + * A iio driver for the light sensor ISL29028.
 + * ISL29028 is Concurrent Ambient Light and Proximity Sensor
 + *
 + * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms and conditions of the GNU General Public License,
 + * version 2, as published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope it will be useful, but WITHOUT
 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 + * more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program.  If not, see http://www.gnu.org/licenses/.
 + */
 +
 +#include linux/module.h
 +#include linux/i2c.h
 +#include linux/err.h
 +#include linux/mutex.h
 +#include linux/delay.h
 +#include linux/slab.h
 +#include linux/regmap.h
 +#include ../iio.h
 +#include ../sysfs.h
 +
 +#define CONVERSION_TIME_MS   100
 +
 +#define ISL29028_REG_CONFIGURE   0x01
 +
 +#define CONFIGURE_ALS_IR_MODE_ALS0
 +#define CONFIGURE_ALS_IR_MODE_IR BIT(0)
 +#define CONFIGURE_ALS_IR_MODE_MASK   BIT(0)
 +
 +#define CONFIGURE_ALS_RANGE_LOW_LUX  0
 +#define CONFIGURE_ALS_RANGE_HIGH_LUX BIT(1)
 +#define CONFIGURE_ALS_RANGE_MASK BIT(1)
 +
 +#define CONFIGURE_ALS_DIS0
 +#define CONFIGURE_ALS_EN BIT(2)
 +#define CONFIGURE_ALS_EN_MASKBIT(2)
 +
 +#define CONFIGURE_PROX_DRIVE BIT(3)
 +
 +#define CONFIGURE_PROX_SLP_SH4
 +#define CONFIGURE_PROX_SLP_MASK  (7  CONFIGURE_PROX_SLP_SH)
 +
 +#define CONFIGURE_PROX_ENBIT(7)
 +#define CONFIGURE_PROX_EN_MASK   BIT(7)
 +
 +#define ISL29028_REG_INTERRUPT   0x02
 +
 +#define ISL29028_REG_PROX_DATA   0x08
 +#define ISL29028_REG_ALSIR_L 0x09
 +#define ISL29028_REG_ALSIR_U 0x0A
 +
 +#define ISL29028_REG_TEST1_MODE  0x0E
 +#define ISL29028_REG_TEST2_MODE  0x0F
 +
 +#define ISL29028_MAX_REGS(ISL29028_REG_TEST2_MODE + 1)
 +
 +enum als_ir_mode {
 + MODE_NONE = 0,
 + MODE_ALS,
 + MODE_IR
 +};
 +
 +struct isl29028_chip {
 + struct device   *dev;
 + struct mutexlock;
 +
 + int prox_period;
 + boolenable_prox;
 +
 + int lux_scale;
 + int als_ir_mode;
 +
 + struct regmap   *regmap;
 +};
 +
 +static int isl29028_set_proxim_period(struct isl29028_chip *chip, int period)
 +{
 + static int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0};
 + int sel;
 +
 + for (sel = 0; sel  ARRAY_SIZE(prox_period); ++sel) {

Re: [PATCH V2 1/2] staging: iio: add driver for isl29028

2012-04-12 Thread Dan Carpenter
On Thu, Apr 12, 2012 at 12:38:11PM +0530, Laxman Dewangan wrote:
 Intersil's ISL29028 is concurrent Ambient Light and
 Proximity Sensor device.
 Add driver to access the light and IR intensity and
 proximity value via iio interface.
 
 Signed-off-by: Laxman Dewangan ldewan...@nvidia.com
 ---
 Taken care of all review comment from Dan.

Looks nice.  You went above and beyond and cleaned up a couple
things I didn't mention.  Thanks.

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


re: mfd: mc13xxx: add codec platform data

2012-05-21 Thread Dan Carpenter
Hello Philippe Rétornaz,

This is a semi-automatic email about new static checker warnings.

The patch e3a0871c8f67: mfd: mc13xxx: add codec platform data from 
May 15, 2012, leads to the following Smatch complaint:

drivers/mfd/mc13xxx-core.c:695 mc13xxx_common_init()
 error: we previously assumed 'pdata' could be null (see line 687)

drivers/mfd/mc13xxx-core.c
   686  
   687  if (mc13xxx_probe_flags_dt(mc13xxx)  0  pdata)
  ^^
Old check.

   688  mc13xxx-flags = pdata-flags;
   689  
   690  if (mc13xxx-flags  MC13XXX_USE_ADC)
   691  mc13xxx_add_subdevice(mc13xxx, %s-adc);
   692  
   693  if (mc13xxx-flags  MC13XXX_USE_CODEC)
   694  mc13xxx_add_subdevice_pdata(mc13xxx, %s-codec,
   695  pdata-codec, 
sizeof(*pdata-codec));

New dereference.

   696  
   697  if (mc13xxx-flags  MC13XXX_USE_RTC)

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


re: regulator: tps65217: Add device tree support

2012-07-13 Thread Dan Carpenter
Hello AnilKumar Ch,

This is a semi-automatic email about new static checker warnings.

The patch a7f1b63eb856: regulator: tps65217: Add device tree 
support from Jul 10, 2012, leads to the following Smatch complaint:

drivers/mfd/tps65217.c:245 tps65217_probe()
 error: we previously assumed 'pdata' could be null (see line 205)

drivers/mfd/tps65217.c
   204  
   205  if (!pdata  client-dev.of_node)
^^
New check.

   206  pdata = tps65217_parse_dt(client);
   207  
   208  tps = devm_kzalloc(client-dev, sizeof(*tps), GFP_KERNEL);
   209  if (!tps)
   210  return -ENOMEM;
   211  
   212  tps-pdata = pdata;
   213  tps-regmap = devm_regmap_init_i2c(client, 
tps65217_regmap_config);
   214  if (IS_ERR(tps-regmap)) {
   215  ret = PTR_ERR(tps-regmap);
   216  dev_err(tps-dev, Failed to allocate register map: 
%d\n,
   217  ret);
   218  return ret;
   219  }
   220  
   221  i2c_set_clientdata(client, tps);
   222  tps-dev = client-dev;
   223  
   224  ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, version);
   225  if (ret  0) {
   226  dev_err(tps-dev, Failed to read revision register: 
%d\n,
   227  ret);
   228  return ret;
   229  }
   230  
   231  dev_info(tps-dev, TPS65217 ID %#x version 1.%d\n,
   232  (version  TPS65217_CHIPID_CHIP_MASK)  4,
   233  version  TPS65217_CHIPID_REV_MASK);
   234  
   235  for (i = 0; i  TPS65217_NUM_REGULATOR; i++) {
   236  struct platform_device *pdev;
   237  
   238  pdev = platform_device_alloc(tps65217-pmic, i);
   239  if (!pdev) {
   240  dev_err(tps-dev, Cannot create regulator 
%d\n, i);
   241  continue;
   242  }
   243  
   244  pdev-dev.parent = tps-dev;
   245  pdev-dev.of_node = pdata-of_node[i];
^^
Old dereference.

   246  reg_data = pdata-tps65217_init_data[i];
   247  platform_device_add_data(pdev, reg_data, 
sizeof(*reg_data));

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] driver-core: dev_to_node() should handle NULL pointers

2012-07-20 Thread Dan Carpenter
What prompted this patch is that in dma_pool_create() we call
dev_to_node() before checking whether dev is NULL.  It looks like
there are places which call dma_pool_create() with a NULL pointer.  An
example is in drivers/usb/gadget/amd5536udc.c.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com
---
Static checker fix.

diff --git a/include/linux/device.h b/include/linux/device.h
index aa7b3b4..c80e7a8d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);
 #ifdef CONFIG_NUMA
 static inline int dev_to_node(struct device *dev)
 {
-   return dev-numa_node;
+   if (dev)
+   return dev-numa_node;
+   return -1;
 }
 static inline void set_dev_node(struct device *dev, int node)
 {
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [patch] driver-core: dev_to_node() should handle NULL pointers

2012-07-20 Thread Dan Carpenter
On Fri, Jul 20, 2012 at 08:00:42AM -0700, Greg Kroah-Hartman wrote:
 On Fri, Jul 20, 2012 at 09:56:23AM +0300, Dan Carpenter wrote:
  What prompted this patch is that in dma_pool_create() we call
  dev_to_node() before checking whether dev is NULL.  It looks like
  there are places which call dma_pool_create() with a NULL pointer.  An
  example is in drivers/usb/gadget/amd5536udc.c.
  
  Signed-off-by: Dan Carpenter dan.carpen...@oracle.com
  ---
  Static checker fix.
  
  diff --git a/include/linux/device.h b/include/linux/device.h
  index aa7b3b4..c80e7a8d 100644
  --- a/include/linux/device.h
  +++ b/include/linux/device.h
  @@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, 
  ...);
   #ifdef CONFIG_NUMA
   static inline int dev_to_node(struct device *dev)
   {
  -   return dev-numa_node;
  +   if (dev)
  +   return dev-numa_node;
  +   return -1;
 
 What happens if this function returns -1?  Can the callers properly
 handle this?
 

Gar.  Now I'm not sure any more.

-1 means no affinity and it's what the dev_to_node() returns if NUMA
is disabled.  But now I think probably it's important to get the
NUMA node correct in dma_pool_create() so this isn't the right
answer.

dma_pool_create() is not correct.  It has code to handle a NULL
dev pointer, but the dev_to_node() dereference will cause an oops
before we reach it.  I'm think this is a real issue that affects a
couple drivers.  Maybe those people compile without NUMA?

I'm not sure the right fix now.

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] video: mb862xxfb: prevent divide by zero bug

2012-08-18 Thread Dan Carpenter
Do a sanity check on these before using them as divisors.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/video/mb862xx/mb862xxfbdrv.c 
b/drivers/video/mb862xx/mb862xxfbdrv.c
index 00ce1f3..57d940b 100644
--- a/drivers/video/mb862xx/mb862xxfbdrv.c
+++ b/drivers/video/mb862xx/mb862xxfbdrv.c
@@ -328,6 +328,8 @@ static int mb862xxfb_ioctl(struct fb_info *fbi, unsigned 
int cmd,
case MB862XX_L1_SET_CFG:
if (copy_from_user(l1_cfg, argp, sizeof(*l1_cfg)))
return -EFAULT;
+   if (l1_cfg-dh == 0 || l1_cfg-dw == 0)
+   return -EINVAL;
if ((l1_cfg-sw = l1_cfg-dw)  (l1_cfg-sh = l1_cfg-dh)) {
/* downscaling */
outreg(cap, GC_CAP_CSC,
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] usb: phy: signedness bug in suspend/resume

2012-09-14 Thread Dan Carpenter
ret should be signed here for the error handling to work.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
index 15ab3d6..d36c282 100644
--- a/drivers/usb/phy/omap-usb2.c
+++ b/drivers/usb/phy/omap-usb2.c
@@ -120,7 +120,7 @@ static int omap_usb_set_peripheral(struct usb_otg *otg,
 
 static int omap_usb2_suspend(struct usb_phy *x, int suspend)
 {
-   u32 ret;
+   int ret;
struct omap_usb *phy = phy_to_omapusb(x);
 
if (suspend  !phy-is_suspended) {
@@ -223,7 +223,7 @@ static int omap_usb2_runtime_suspend(struct device *dev)
 
 static int omap_usb2_runtime_resume(struct device *dev)
 {
-   u32 ret = 0;
+   int ret;
struct platform_device  *pdev = to_platform_device(dev);
struct omap_usb *phy = platform_get_drvdata(pdev);
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


re: spi-gpio: allow operation without CS signal

2012-10-03 Thread Dan Carpenter
Hello Michael Buesch,

The patch bfb9bcdbda9a: spi-gpio: allow operation without CS signal
from Apr 2, 2009, leads to the following Clang warning:
drivers/spi/spi-gpio.c:229:9: warning: comparison of constant
18446744073709551615 with expression of type 'unsigned int' is always
true [-Wtautological-constant-out-of-range-compare]


#define SPI_GPIO_NO_CHIPSELECT  ((unsigned long)-1l)
 ^^

drivers/spi/spi-gpio.c
   223  unsigned int cs = spi_gpio-cs_gpios[spi-chip_select];
   224  
   225  /* set initial clock polarity */
   226  if (is_active)
   227  setsck(spi, spi-mode  SPI_CPOL);
   228  
   229  if (cs != SPI_GPIO_NO_CHIPSELECT) {

This is always true.  SPI_GPIO_NO_CHIPSELECT is used like this through
out.  The comments say that it's supposed to be used as a void pointer
but that doesn't make a lot of sense either.

   230  /* SPI is normally active-low */
   231  gpio_set_value(cs, (spi-mode  SPI_CS_HIGH) ? 
is_active : !is_active);
   232  }

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] tg3: missing break statement in tg3_get_5720_nvram_info()

2013-01-11 Thread Dan Carpenter
There is a missing break statement so FLASH_5762_EEPROM_HD gets treated
like FLASH_5762_EEPROM_LD.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com
---
Only needed in linux-next.

diff --git a/drivers/net/ethernet/broadcom/tg3.c 
b/drivers/net/ethernet/broadcom/tg3.c
index bc4d989..642764e 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -13726,8 +13726,10 @@ static void tg3_get_5720_nvram_info(struct tg3 *tp)
switch (nvmpinstrp) {
case FLASH_5762_EEPROM_HD:
nvmpinstrp = FLASH_5720_EEPROM_HD;
+   break;
case FLASH_5762_EEPROM_LD:
nvmpinstrp = FLASH_5720_EEPROM_LD;
+   break;
}
}
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] hwmon/max6697: fix memset size in max6697_init_chip()

2013-01-14 Thread Dan Carpenter
sizeof(p) was intended instead of sizeof(data).  data is a pointer and
p is a 7 character struct.  It probably doesn't make a difference most
of the time, but it could result in using uninitialized data.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c
index a1c8c0a..d229cc7 100644
--- a/drivers/hwmon/max6697.c
+++ b/drivers/hwmon/max6697.c
@@ -474,7 +474,7 @@ static int max6697_init_chip(struct i2c_client *client)
return 0;
 
if (!pdata || client-dev.of_node) {
-   memset(p, 0, sizeof(data));
+   memset(p, 0, sizeof(p));
max6697_get_config_of(client-dev.of_node, p);
pdata = p;
}
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] ALSA: ASoC: tas5086: signedness bug in tas5086_hw_params()

2013-03-12 Thread Dan Carpenter
val has to be signed for the error handling to work.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/sound/soc/codecs/tas5086.c b/sound/soc/codecs/tas5086.c
index 008bea4..41d03ae 100644
--- a/sound/soc/codecs/tas5086.c
+++ b/sound/soc/codecs/tas5086.c
@@ -251,7 +251,7 @@ static int tas5086_hw_params(struct snd_pcm_substream 
*substream,
 {
struct snd_soc_codec *codec = dai-codec;
struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
-   unsigned int val;
+   int val;
int ret;
 
priv-rate = params_rate(params);
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] mtd: denali_dt: harmless case of testing the wrong variable

2013-04-01 Thread Dan Carpenter
There is a warning message that can't be printed because we test the
wrong variable.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/mtd/nand/denali_dt.c b/drivers/mtd/nand/denali_dt.c
index 546f8cb..02988b0 100644
--- a/drivers/mtd/nand/denali_dt.c
+++ b/drivers/mtd/nand/denali_dt.c
@@ -42,7 +42,7 @@ static void __iomem *request_and_map(struct device *dev,
}
 
ptr = devm_ioremap_nocache(dev, res-start, resource_size(res));
-   if (!res)
+   if (!ptr)
dev_err(dev, ioremap_nocache of %s failed!, res-name);
 
return ptr;
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch -next] net: calxedaxgmac: fix condition in xgmac_set_features()

2013-04-25 Thread Dan Carpenter
The changed variable should be a 64 bit type, otherwise it can't store
all the features.  The way the code is now the test for whether
NETIF_F_RXCSUM changed is always false and we return immediately.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/net/ethernet/calxeda/xgmac.c 
b/drivers/net/ethernet/calxeda/xgmac.c
index 791e5ff..4a1f2fa 100644
--- a/drivers/net/ethernet/calxeda/xgmac.c
+++ b/drivers/net/ethernet/calxeda/xgmac.c
@@ -1482,7 +1482,7 @@ static int xgmac_set_features(struct net_device *dev, 
netdev_features_t features
u32 ctrl;
struct xgmac_priv *priv = netdev_priv(dev);
void __iomem *ioaddr = priv-base;
-   u32 changed = dev-features ^ features;
+   netdev_features_t changed = dev-features ^ features;
 
if (!(changed  NETIF_F_RXCSUM))
return 0;
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


re: regulator: palma: add ramp delay support through regulator constraints

2013-04-29 Thread Dan Carpenter
Hello Laxman Dewangan,

The patch 28d1e8cd671a: regulator: palma: add ramp delay support
through regulator constraints from Apr 18, 2013, leads to the
following Smatch warning:
drivers/regulator/palmas-regulator.c:843 palmas_regulators_probe()
 warn: was || intended here instead of ?

drivers/regulator/palmas-regulator.c
   842  
   843  if ((id == PALMAS_REG_SMPS6)  (id == 
PALMAS_REG_SMPS8))

id can't be equal to both.

   844  ramp_delay_support = true;
   845  
   846  if (ramp_delay_support) {
   847  addr = palmas_regs_info[id].tstep_addr;
   848  ret = palmas_smps_read(pmic-palmas, addr, 
reg);
   849  if (ret  0) {

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch -next] spi: spi-xilinx: cleanup a check in xilinx_spi_txrx_bufs()

2013-06-09 Thread Dan Carpenter
'!' has higher precedence than comparisons so the original condition
is equivalent to if (xspi-remaining_bytes == 0).  This makes the
static checkers complain.

xspi-remaining_bytes is signed and from looking at the code
briefly, I think it might be able to go negative.  I suspect that
going negative may cause a bug, but I don't have the hardware and
can't test.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index 0b8398c..fb56fcf 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -301,7 +301,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, 
struct spi_transfer *t)
}
 
/* See if there is more data to send */
-   if (!xspi-remaining_bytes  0)
+   if (xspi-remaining_bytes = 0)
break;
}
 
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] spi/xilinx: signedness issue checking platform_get_irq()

2013-07-17 Thread Dan Carpenter
xspi-irq is unsigned int so it's never less than zero.  I have added
a cast.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index fea815c..e5201fb 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -442,7 +442,7 @@ static int xilinx_spi_probe(struct platform_device *pdev)
xspi_init_hw(xspi);
 
xspi-irq = platform_get_irq(pdev, 0);
-   if (xspi-irq  0) {
+   if ((int)xspi-irq  0) {
ret = xspi-irq;
goto put_master;
}
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [patch] spi/xilinx: signedness issue checking platform_get_irq()

2013-07-17 Thread Dan Carpenter
On Wed, Jul 17, 2013 at 09:03:53AM -0600, Stephen Warren wrote:
 On 07/17/2013 06:26 AM, Dan Carpenter wrote:
  xspi-irq is unsigned int so it's never less than zero.  I have added
  a cast.
 
 Um. Doesn't this just hide a warning, not solve the problem? If the
 value can't be negative, so the if condition never fires, then the cast
 won't change that...

No.  It fixes the problem but Mark is right that it's ugly.  Sorry
for that.  I will resend.

regards,
dan carpenter

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch v2] spi/xilinx: signedness issue checking platform_get_irq()

2013-07-17 Thread Dan Carpenter
In xilinx_spi_probe() we use xspi-irq to store negative error codes so
it has to be signed.  We weren't going to use the upper bit any way so
this is fine.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com
---
v2:  The first version introduced an ugly cast.  Sorry for that.

diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index fea815c..0f4a093 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -82,7 +82,7 @@ struct xilinx_spi {
struct completion done;
void __iomem*regs;  /* virt. address of the control registers */
 
-   u32 irq;
+   int irq;
 
u8 *rx_ptr; /* pointer in the Tx buffer */
const u8 *tx_ptr;   /* pointer in the Rx buffer */
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss