[patch] hvc_xen: NULL dereference on allocation failure

2012-05-15 Thread Dan Carpenter
If kzalloc() returns a NULL here, we pass a NULL to
xencons_disconnect_backend() which will cause an Oops.

Also I removed the __GFP_ZERO while I was at it since kzalloc() implies
__GFP_ZERO.

Signed-off-by: Dan Carpenter 

diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index 83d5c88..d3d91da 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -430,9 +430,9 @@ static int __devinit xencons_probe(struct xenbus_device 
*dev,
if (devid == 0)
return -ENODEV;
 
-   info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL | __GFP_ZERO);
+   info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL);
if (!info)
-   goto error_nomem;
+   return -ENOMEM;
dev_set_drvdata(&dev->dev, info);
info->xbdev = dev;
info->vtermno = xenbus_devid_to_vtermno(devid);
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [patch] hvc_xen: NULL dereference on allocation failure

2012-05-15 Thread Stefano Stabellini
On Tue, 15 May 2012, Dan Carpenter wrote:
> If kzalloc() returns a NULL here, we pass a NULL to
> xencons_disconnect_backend() which will cause an Oops.
> 
> Also I removed the __GFP_ZERO while I was at it since kzalloc() implies
> __GFP_ZERO.
> 
> Signed-off-by: Dan Carpenter 

Acked-by: Stefano Stabellini 
 
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] pseries/iommu: remove default window before attempting DDW manipulation

2012-05-15 Thread Nishanth Aravamudan
An upcoming release of firmware will add DDW extensions, in particular
an API to "reset" the DMA window to the original configuration (32-bit,
2GB in size). With that API available, we can safely remove the default
window, increasing the resources available to firmware for creation of
larger windows for the slot in question -- if we encounter an error, we
can use the new API to reset the state of the slot.

Further, this same release of firmware will make it a hard requirement
for OSes to release the existing window before any other windows will be
shown as available, to avoid conflicts in addressing between the two
windows.

In anticipation of these changes, always remove the default window
before we do any DDW manipulations.

Signed-off-by: Nishanth Aravamudan 

diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index 0915b1a..526076b 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -707,6 +707,21 @@ static int __init disable_ddw_setup(char *str)
 
 early_param("disable_ddw", disable_ddw_setup);
 
+static inline void __remove_ddw(struct device_node *np, const u32 *ddw_avail, 
u64 liobn)
+{
+   int ret;
+
+   ret = rtas_call(ddw_avail[2], 1, 1, NULL, liobn);
+   if (ret)
+   pr_warning("%s: failed to remove DMA window: rtas returned "
+   "%d to ibm,remove-pe-dma-window(%x) %llx\n",
+   np->full_name, ret, ddw_avail[2], liobn);
+   else
+   pr_debug("%s: successfully removed DMA window: rtas returned "
+   "%d to ibm,remove-pe-dma-window(%x) %llx\n",
+   np->full_name, ret, ddw_avail[2], liobn);
+}
+
 static void remove_ddw(struct device_node *np)
 {
struct dynamic_dma_window_prop *dwp;
@@ -736,15 +751,7 @@ static void remove_ddw(struct device_node *np)
pr_debug("%s successfully cleared tces in window.\n",
 np->full_name);
 
-   ret = rtas_call(ddw_avail[2], 1, 1, NULL, liobn);
-   if (ret)
-   pr_warning("%s: failed to remove direct window: rtas returned "
-   "%d to ibm,remove-pe-dma-window(%x) %llx\n",
-   np->full_name, ret, ddw_avail[2], liobn);
-   else
-   pr_debug("%s: successfully removed direct window: rtas returned 
"
-   "%d to ibm,remove-pe-dma-window(%x) %llx\n",
-   np->full_name, ret, ddw_avail[2], liobn);
+   __remove_ddw(np, ddw_avail, liobn);
 
 delprop:
ret = prom_remove_property(np, win64);
@@ -869,6 +876,35 @@ static int create_ddw(struct pci_dev *dev, const u32 
*ddw_avail,
return ret;
 }
 
+static void restore_default_window(struct pci_dev *dev,
+   u32 ddw_restore_token, unsigned long liobn)
+{
+   struct eeh_dev *edev;
+   u32 cfg_addr;
+   u64 buid;
+   int ret;
+
+   /*
+* Get the config address and phb buid of the PE window.
+* Rely on eeh to retrieve this for us.
+* Retrieve them from the pci device, not the node with the
+* dma-window property
+*/
+   edev = pci_dev_to_eeh_dev(dev);
+   cfg_addr = edev->config_addr;
+   if (edev->pe_config_addr)
+   cfg_addr = edev->pe_config_addr;
+   buid = edev->phb->buid;
+
+   do {
+   ret = rtas_call(ddw_restore_token, 3, 1, NULL, cfg_addr,
+   BUID_HI(buid), BUID_LO(buid));
+   } while (rtas_busy_delay(ret));
+   dev_info(&dev->dev,
+   "ibm,reset-pe-dma-windows(%x) %x %x %x returned %d\n",
+ddw_restore_token, cfg_addr, BUID_HI(buid), BUID_LO(buid), 
ret);
+}
+
 /*
  * If the PE supports dynamic dma windows, and there is space for a table
  * that can map all pages in a linear offset, then setup such a table,
@@ -889,9 +925,13 @@ static u64 enable_ddw(struct pci_dev *dev, struct 
device_node *pdn)
u64 dma_addr, max_addr;
struct device_node *dn;
const u32 *uninitialized_var(ddw_avail);
+   const u32 *uninitialized_var(ddw_extensions);
+   u32 ddw_restore_token = 0;
struct direct_window *window;
struct property *win64;
struct dynamic_dma_window_prop *ddwprop;
+   const void *dma_window = NULL;
+   unsigned long liobn, offset, size;
 
mutex_lock(&direct_window_init_mutex);
 
@@ -911,7 +951,40 @@ static u64 enable_ddw(struct pci_dev *dev, struct 
device_node *pdn)
if (!ddw_avail || len < 3 * sizeof(u32))
goto out_unlock;
 
-   /*
+   /*
+* the extensions property is only required to exist in certain
+* levels of firmware and later
+* the ibm,ddw-extensions property is a list with the first
+* element containing the number of extensions and each
+* subsequent entry is a value corresponding to that extension