[PATCH net-next] hv_netvsc: Fix race condition on Multi-Send Data field

2015-12-10 Thread Haiyang Zhang
In commit 2a04ae8acb14 ("hv_netvsc: remove locking in netvsc_send()"), the
locking for MSD (Multi-Send Data) field was removed. This could cause a
race condition between RNDIS control messages and data packets processing,
because these two types of traffic are not synchronized.
This patch fixes this issue by sending control messages out directly
without reading MSD field.

Signed-off-by: Haiyang Zhang 
Reviewed-by: K. Y. Srinivasan 
---
 drivers/net/hyperv/netvsc.c |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 02bab9a..059fc52 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -867,6 +867,14 @@ int netvsc_send(struct hv_device *device,
packet->send_buf_index = NETVSC_INVALID_INDEX;
packet->cp_partial = false;
 
+   /* Send control message directly without accessing msd (Multi-Send
+* Data) field which may be changed during data packet processing.
+*/
+   if (!skb) {
+   cur_send = packet;
+   goto send_now;
+   }
+
msdp = _device->msd[q_idx];
 
/* batch packets in send buffer if possible */
@@ -939,6 +947,7 @@ int netvsc_send(struct hv_device *device,
}
}
 
+send_now:
if (cur_send)
ret = netvsc_send_pkt(cur_send, net_device, pb, skb);
 
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v10 3/7] PCI: Make it possible to implement a PCI MSI IRQ Domain in a module.

2015-12-10 Thread jakeo
From: Jake Oshins 

The Linux kernel already has the concpet of IRQ domain, wherein a
component can expose a set of IRQs which are managed by a particular
interrupt controller chip or other subsystem. The PCI driver exposes
the notion of an IRQ domain for Message-Signaled Interrupts (MSI) from
PCI Express devices. This patch exposes the functions which are
necessary for making an MSI IRQ domain within a module.

Signed-off-by: Jake Oshins 
---
 arch/x86/include/asm/msi.h| 6 ++
 arch/x86/kernel/apic/msi.c| 8 +---
 arch/x86/kernel/apic/vector.c | 2 ++
 drivers/pci/msi.c | 4 
 kernel/irq/chip.c | 1 +
 kernel/irq/irqdomain.c| 4 
 6 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/msi.h b/arch/x86/include/asm/msi.h
index 93724cc..eb4b09b 100644
--- a/arch/x86/include/asm/msi.h
+++ b/arch/x86/include/asm/msi.h
@@ -1,7 +1,13 @@
 #ifndef _ASM_X86_MSI_H
 #define _ASM_X86_MSI_H
 #include 
+#include 
 
 typedef struct irq_alloc_info msi_alloc_info_t;
 
+int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
+   msi_alloc_info_t *arg);
+
+void pci_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc);
+
 #endif /* _ASM_X86_MSI_H */
diff --git a/arch/x86/kernel/apic/msi.c b/arch/x86/kernel/apic/msi.c
index 5f1feb6..ade2532 100644
--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -96,8 +96,8 @@ static irq_hw_number_t pci_msi_get_hwirq(struct 
msi_domain_info *info,
return arg->msi_hwirq;
 }
 
-static int pci_msi_prepare(struct irq_domain *domain, struct device *dev,
-  int nvec, msi_alloc_info_t *arg)
+int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
+   msi_alloc_info_t *arg)
 {
struct pci_dev *pdev = to_pci_dev(dev);
struct msi_desc *desc = first_pci_msi_entry(pdev);
@@ -113,11 +113,13 @@ static int pci_msi_prepare(struct irq_domain *domain, 
struct device *dev,
 
return 0;
 }
+EXPORT_SYMBOL_GPL(pci_msi_prepare);
 
-static void pci_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc)
+void pci_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc)
 {
arg->msi_hwirq = pci_msi_domain_calc_hwirq(arg->msi_dev, desc);
 }
+EXPORT_SYMBOL_GPL(pci_msi_set_desc);
 
 static struct msi_domain_ops pci_msi_domain_ops = {
.get_hwirq  = pci_msi_get_hwirq,
diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 861bc59..908cb37 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -29,6 +29,7 @@ struct apic_chip_data {
 };
 
 struct irq_domain *x86_vector_domain;
+EXPORT_SYMBOL_GPL(x86_vector_domain);
 static DEFINE_RAW_SPINLOCK(vector_lock);
 static cpumask_var_t vector_cpumask;
 static struct irq_chip lapic_controller;
@@ -66,6 +67,7 @@ struct irq_cfg *irqd_cfg(struct irq_data *irq_data)
 
return data ? >cfg : NULL;
 }
+EXPORT_SYMBOL_GPL(irqd_cfg);
 
 struct irq_cfg *irq_cfg(unsigned int irq)
 {
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 7eaa4c8..7a0df3f 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -257,6 +257,7 @@ void pci_msi_mask_irq(struct irq_data *data)
 {
msi_set_mask_bit(data, 1);
 }
+EXPORT_SYMBOL_GPL(pci_msi_mask_irq);
 
 /**
  * pci_msi_unmask_irq - Generic irq chip callback to unmask PCI/MSI interrupts
@@ -266,6 +267,7 @@ void pci_msi_unmask_irq(struct irq_data *data)
 {
msi_set_mask_bit(data, 0);
 }
+EXPORT_SYMBOL_GPL(pci_msi_unmask_irq);
 
 void default_restore_msi_irqs(struct pci_dev *dev)
 {
@@ -1126,6 +1128,7 @@ struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc)
 {
return to_pci_dev(desc->dev);
 }
+EXPORT_SYMBOL(msi_desc_to_pci_dev);
 
 void *msi_desc_to_pci_sysdata(struct msi_desc *desc)
 {
@@ -1285,6 +1288,7 @@ struct irq_domain *pci_msi_create_irq_domain(struct 
fwnode_handle *fwnode,
domain->bus_token = DOMAIN_BUS_PCI_MSI;
return domain;
 }
+EXPORT_SYMBOL_GPL(pci_msi_create_irq_domain);
 
 /**
  * pci_msi_domain_alloc_irqs - Allocate interrupts for @dev in @domain
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index 05e29de..5797909 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -950,6 +950,7 @@ void irq_chip_ack_parent(struct irq_data *data)
data = data->parent_data;
data->chip->irq_ack(data);
 }
+EXPORT_SYMBOL_GPL(irq_chip_ack_parent);
 
 /**
  * irq_chip_mask_parent - Mask the parent interrupt
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 22aa961..aa6ac44 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -60,6 +60,7 @@ struct fwnode_handle *irq_domain_alloc_fwnode(void *data)
fwid->fwnode.type = FWNODE_IRQCHIP;
return >fwnode;
 }
+EXPORT_SYMBOL_GPL(irq_domain_alloc_fwnode);
 
 /**
  * irq_domain_free_fwnode - Free a non-OF-backed fwnode_handle
@@ -77,6 +78,7 @@ void 

[PATCH v10 1/7] drivers:hv: Export a function that maps Linux CPU num onto Hyper-V proc num

2015-12-10 Thread jakeo
From: Jake Oshins 

This patch exposes the mapping between Linux CPU number and Hyper-V
virtual processor number. This is necessary because the hypervisor needs
to know which virtual processor to target when making a mapping in the
Interrupt Redirection Table in the I/O MMU.

Signed-off-by: Jake Oshins 
---
 drivers/hv/vmbus_drv.c | 17 +
 include/linux/hyperv.h |  2 ++
 2 files changed, 19 insertions(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index f19b6f7..c89d0e5 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1191,6 +1191,23 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
 }
 EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
 
+/**
+ * vmbus_cpu_number_to_vp_number() - Map CPU to VP.
+ * @cpu_number: CPU number in Linux terms
+ *
+ * This function returns the mapping between the Linux processor
+ * number and the hypervisor's virtual processor number, useful
+ * in making hypercalls and such that talk about specific
+ * processors.
+ *
+ * Return: Virtual processor number in Hyper-V terms
+ */
+int vmbus_cpu_number_to_vp_number(int cpu_number)
+{
+   return hv_context.vp_index[cpu_number];
+}
+EXPORT_SYMBOL_GPL(vmbus_cpu_number_to_vp_number);
+
 static int vmbus_acpi_add(struct acpi_device *device)
 {
acpi_status result;
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 8fdc17b..fddb3e0 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -983,6 +983,8 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
resource_size_t size, resource_size_t align,
bool fb_overlap_ok);
 
+int vmbus_cpu_number_to_vp_number(int cpu_number);
+
 /**
  * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  *
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v10 3/7] PCI: Make it possible to implement a PCI MSI IRQ Domain in a module.

2015-12-10 Thread Marc Zyngier
On 10/12/15 17:52, ja...@microsoft.com wrote:
> From: Jake Oshins 
> 
> The Linux kernel already has the concpet of IRQ domain, wherein a
> component can expose a set of IRQs which are managed by a particular
> interrupt controller chip or other subsystem. The PCI driver exposes
> the notion of an IRQ domain for Message-Signaled Interrupts (MSI) from
> PCI Express devices. This patch exposes the functions which are
> necessary for making an MSI IRQ domain within a module.
> 
> Signed-off-by: Jake Oshins 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v10 7/7] PCI: hv: New paravirtual PCI front-end for Hyper-V VMs

2015-12-10 Thread jakeo
From: Jake Oshins 

This patch introduces a new driver which exposes a root PCI bus whenever a
PCI Express device is passed through to a guest VM under Hyper-V. The
device can be single- or multi-function. The interrupts for the devices
are managed by an IRQ domain, implemented within the driver.

Signed-off-by: Jake Oshins 
---
 MAINTAINERS|1 +
 drivers/pci/Kconfig|7 +
 drivers/pci/host/Makefile  |1 +
 drivers/pci/host/hv_pcifront.c | 2249 
 4 files changed, 2258 insertions(+)
 create mode 100644 drivers/pci/host/hv_pcifront.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e6ec986..40747e8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5115,6 +5115,7 @@ F:arch/x86/kernel/cpu/mshyperv.c
 F: drivers/hid/hid-hyperv.c
 F: drivers/hv/
 F: drivers/input/serio/hyperv-keyboard.c
+F: drivers/pci/host/hv_pcifront.c
 F: drivers/net/hyperv/
 F: drivers/scsi/storvsc_drv.c
 F: drivers/video/fbdev/hyperv_fb.c
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 73de4ef..573b8d6 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -118,4 +118,11 @@ config PCI_LABEL
def_bool y if (DMI || ACPI)
select NLS
 
+config HYPERV_VPCI
+tristate "Hyper-V PCI Frontend"
+depends on PCI && X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && 
X86_64
+help
+  The PCI device frontend driver allows the kernel to import arbitrary
+  PCI devices from a PCI backend to support PCI driver domains.
+
 source "drivers/pci/host/Kconfig"
diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile
index 9d4d3c6..d9abd2a 100644
--- a/drivers/pci/host/Makefile
+++ b/drivers/pci/host/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_PCIE_DW) += pcie-designware.o
 obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
 obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
+obj-$(CONFIG_HYPERV_VPCI) += hv_pcifront.o
 obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
 obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
 obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o
diff --git a/drivers/pci/host/hv_pcifront.c b/drivers/pci/host/hv_pcifront.c
new file mode 100644
index 000..56da07e
--- /dev/null
+++ b/drivers/pci/host/hv_pcifront.c
@@ -0,0 +1,2249 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Author:
+ *   Jake Oshins 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Protocol versions. The low word is the minor version, the high word the 
major
+ * version.
+ */
+
+#define PCI_MAKE_VERSION(major, minor) ((__u32)(((major) << 16) | (major)))
+#define PCI_MAJOR_VERSION(version) ((__u32)(version) >> 16)
+#define PCI_MINOR_VERSION(version) ((__u32)(version) & 0xff)
+
+enum {
+   PCI_PROTOCOL_VERSION_1_1 = PCI_MAKE_VERSION(1, 1),
+   PCI_PROTOCOL_VERSION_CURRENT = PCI_PROTOCOL_VERSION_1_1
+};
+
+#define PCI_CONFIG_MMIO_LENGTH 0x2000
+#define MAX_SUPPORTED_MSI_MESSAGES 0x400
+
+/*
+ * Message Types
+ */
+
+enum pci_message_type {
+   /*
+* Version 1.1
+*/
+   PCI_MESSAGE_BASE= 0x4249,
+   PCI_BUS_RELATIONS   = PCI_MESSAGE_BASE + 0,
+   PCI_QUERY_BUS_RELATIONS = PCI_MESSAGE_BASE + 1,
+   PCI_POWER_STATE_CHANGE  = PCI_MESSAGE_BASE + 4,
+   PCI_QUERY_RESOURCE_REQUIREMENTS = PCI_MESSAGE_BASE + 5,
+   PCI_QUERY_RESOURCE_RESOURCES= PCI_MESSAGE_BASE + 6,
+   PCI_BUS_D0ENTRY = PCI_MESSAGE_BASE + 7,
+   PCI_BUS_D0EXIT  = PCI_MESSAGE_BASE + 8,
+   PCI_READ_BLOCK  = PCI_MESSAGE_BASE + 9,
+   PCI_WRITE_BLOCK = PCI_MESSAGE_BASE + 0xA,
+   PCI_EJECT   = PCI_MESSAGE_BASE + 0xB,
+   PCI_QUERY_STOP  = PCI_MESSAGE_BASE + 0xC,
+   PCI_REENABLE= PCI_MESSAGE_BASE + 0xD,
+   PCI_QUERY_STOP_FAILED   = PCI_MESSAGE_BASE + 0xE,
+   PCI_EJECTION_COMPLETE   = PCI_MESSAGE_BASE + 0xF,
+   PCI_RESOURCES_ASSIGNED  = PCI_MESSAGE_BASE + 0x10,
+   PCI_RESOURCES_RELEASED  = PCI_MESSAGE_BASE + 0x11,
+   PCI_INVALIDATE_BLOCK= PCI_MESSAGE_BASE + 0x12,
+   PCI_QUERY_PROTOCOL_VERSION  = PCI_MESSAGE_BASE + 0x13,
+   

[PATCH v10 2/7] drivers:hv: Export hv_do_hypercall()

2015-12-10 Thread jakeo
From: Jake Oshins 

This patch exposes the function that hv_vmbus.ko uses to make hypercalls.
This is necessary for retargeting an interrupt when it is given a new
affinity and vector.

Signed-off-by: Jake Oshins 
---
 drivers/hv/hv.c   | 20 ++--
 drivers/hv/hyperv_vmbus.h |  2 +-
 include/linux/hyperv.h|  1 +
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 6341be8..7a06933 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -89,9 +89,9 @@ static int query_hypervisor_info(void)
 }
 
 /*
- * do_hypercall- Invoke the specified hypercall
+ * hv_do_hypercall- Invoke the specified hypercall
  */
-static u64 do_hypercall(u64 control, void *input, void *output)
+u64 hv_do_hypercall(u64 control, void *input, void *output)
 {
u64 input_address = (input) ? virt_to_phys(input) : 0;
u64 output_address = (output) ? virt_to_phys(output) : 0;
@@ -132,6 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void 
*output)
return hv_status_lo | ((u64)hv_status_hi << 32);
 #endif /* !x86_64 */
 }
+EXPORT_SYMBOL_GPL(hv_do_hypercall);
 
 #ifdef CONFIG_X86_64
 static cycle_t read_hv_clock_tsc(struct clocksource *arg)
@@ -315,7 +316,7 @@ int hv_post_message(union hv_connection_id connection_id,
 {
 
struct hv_input_post_message *aligned_msg;
-   u16 status;
+   u64 status;
 
if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
return -EMSGSIZE;
@@ -329,11 +330,10 @@ int hv_post_message(union hv_connection_id connection_id,
aligned_msg->payload_size = payload_size;
memcpy((void *)aligned_msg->payload, payload, payload_size);
 
-   status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL)
-   & 0x;
+   status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL);
 
put_cpu();
-   return status;
+   return status & 0x;
 }
 
 
@@ -343,13 +343,13 @@ int hv_post_message(union hv_connection_id connection_id,
  *
  * This involves a hypercall.
  */
-u16 hv_signal_event(void *con_id)
+int hv_signal_event(void *con_id)
 {
-   u16 status;
+   u64 status;
 
-   status = (do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL) & 0x);
+   status = hv_do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL);
 
-   return status;
+   return status & 0x;
 }
 
 static int hv_ce_set_next_event(unsigned long delta,
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 3782636..cc2fb53 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -582,7 +582,7 @@ extern int hv_post_message(union hv_connection_id 
connection_id,
 enum hv_message_type message_type,
 void *payload, size_t payload_size);
 
-extern u16 hv_signal_event(void *con_id);
+extern int hv_signal_event(void *con_id);
 
 extern int hv_synic_alloc(void);
 
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index fddb3e0..24d0b65 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -984,6 +984,7 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
bool fb_overlap_ok);
 
 int vmbus_cpu_number_to_vp_number(int cpu_number);
+u64 hv_do_hypercall(u64 control, void *input, void *output);
 
 /**
  * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v10 5/7] PCI: irqdomain: Look up IRQ domain by fwnode_handle

2015-12-10 Thread Marc Zyngier
On 10/12/15 17:53, ja...@microsoft.com wrote:
> From: Jake Oshins 
> 
> This patch adds a second way of finding an IRQ domain associated with
> a root PCI bus.  After looking to see if one can be found through
> the OF tree, it attempts to look up the IRQ domain through an
> fwnode_handle stored in the pci_sysdata struct.
> 
> Signed-off-by: Jake Oshins 
> ---
>  drivers/pci/probe.c | 14 ++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 750f907..c6369dd 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -674,6 +674,20 @@ static struct irq_domain 
> *pci_host_bridge_msi_domain(struct pci_bus *bus)
>*/
>   d = pci_host_bridge_of_msi_domain(bus);
>  
> +#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
> + /*
> +  * If no IRQ domain was found via the OF tree, try looking it up
> +  * directly through the fwnode_handle.
> +  */
> + if (!d) {
> + struct fwnode_handle *fwnode = pci_root_bus_fwnode(bus);
> +
> + if (fwnode)
> + d = irq_find_matching_fwnode(fwnode,
> +  DOMAIN_BUS_PCI_MSI);
> + }
> +#endif
> +
>   return d;
>  }
>  
> 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] storvsc: add logging for error/warning messages

2015-12-10 Thread Martin K. Petersen
> "Long" == Long Li  writes:

Long> Introduce a logging level for storvsc to log certain error/warning
Long> messages. Those messages are helpful in some environments,
Long> e.g. Microsoft Azure, for customer support and troubleshooting
Long> purposes.

Applied to 4.5/scsi-queue.

-- 
Martin K. Petersen  Oracle Linux Engineering
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 25/58] mtd: nand: jz4740: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/jz4740_nand.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
index 5a06fba..03239a5 100644
--- a/drivers/mtd/nand/jz4740_nand.c
+++ b/drivers/mtd/nand/jz4740_nand.c
@@ -59,7 +59,6 @@
 #define JZ_NAND_MEM_ADDR_OFFSET 0x1
 
 struct jz_nand {
-   struct mtd_info mtd;
struct nand_chip chip;
void __iomem *base;
struct resource *mem;
@@ -76,7 +75,7 @@ struct jz_nand {
 
 static inline struct jz_nand *mtd_to_jz_nand(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct jz_nand, mtd);
+   return container_of(mtd_to_nand(mtd), struct jz_nand, chip);
 }
 
 static void jz_nand_select_chip(struct mtd_info *mtd, int chipnr)
@@ -334,8 +333,8 @@ static int jz_nand_detect_bank(struct platform_device *pdev,
char gpio_name[9];
char res_name[6];
uint32_t ctrl;
-   struct mtd_info *mtd = >mtd;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
/* Request GPIO port. */
gpio = JZ_GPIO_MEM_CS0 + bank - 1;
@@ -432,8 +431,8 @@ static int jz_nand_probe(struct platform_device *pdev)
goto err_iounmap_mmio;
}
 
-   mtd = >mtd;
chip= >chip;
+   mtd = nand_to_mtd(chip);
mtd->priv   = chip;
mtd->dev.parent = >dev;
mtd->name   = "jz4740-nand";
@@ -543,7 +542,7 @@ static int jz_nand_remove(struct platform_device *pdev)
struct jz_nand *nand = platform_get_drvdata(pdev);
size_t i;
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
/* Deassert and disable all chips */
writel(0, nand->base + JZ_REG_NAND_CTRL);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 30/58] mtd: nand: ndfc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/ndfc.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index d8a23b0..3a7168e 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -37,7 +37,6 @@
 struct ndfc_controller {
struct platform_device *ofdev;
void __iomem *ndfcbase;
-   struct mtd_info mtd;
struct nand_chip chip;
int chip_select;
struct nand_hw_control ndfc_control;
@@ -147,6 +146,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 {
struct device_node *flash_np;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
int ret;
 
chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
@@ -167,31 +167,32 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
chip->ecc.strength = 1;
chip->priv = ndfc;
 
-   ndfc->mtd.priv = chip;
-   ndfc->mtd.dev.parent = >ofdev->dev;
+   mtd->priv = chip;
+   mtd->dev.parent = >ofdev->dev;
 
flash_np = of_get_next_child(node, NULL);
if (!flash_np)
return -ENODEV;
nand_set_flash_node(chip, flash_np);
 
-   ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s",
-   dev_name(>ofdev->dev), flash_np->name);
-   if (!ndfc->mtd.name) {
+   ppdata.of_node = flash_np;
+   mtd->name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(>ofdev->dev),
+ flash_np->name);
+   if (!mtd->name) {
ret = -ENOMEM;
goto err;
}
 
-   ret = nand_scan(>mtd, 1);
+   ret = nand_scan(mtd, 1);
if (ret)
goto err;
 
-   ret = mtd_device_register(>mtd, NULL, 0);
+   ret = mtd_device_register(mtd, NULL, 0);
 
 err:
of_node_put(flash_np);
if (ret)
-   kfree(ndfc->mtd.name);
+   kfree(mtd->name);
return ret;
 }
 
@@ -258,9 +259,10 @@ static int ndfc_probe(struct platform_device *ofdev)
 static int ndfc_remove(struct platform_device *ofdev)
 {
struct ndfc_controller *ndfc = dev_get_drvdata(>dev);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
-   nand_release(>mtd);
-   kfree(ndfc->mtd.name);
+   nand_release(mtd);
+   kfree(mtd->name);
 
return 0;
 }
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 29/58] mtd: nand: nandsim: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/nandsim.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index eb2a567..442eeaf 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2236,13 +2236,13 @@ static int __init ns_init_module(void)
}
 
/* Allocate and initialize mtd_info, nand_chip and nandsim structures */
-   nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
-   + sizeof(struct nandsim), GFP_KERNEL);
-   if (!nsmtd) {
+   chip = kzalloc(sizeof(struct nand_chip) + sizeof(struct nandsim),
+  GFP_KERNEL);
+   if (!chip) {
NS_ERR("unable to allocate core structures.\n");
return -ENOMEM;
}
-   chip= (struct nand_chip *)(nsmtd + 1);
+   nsmtd   = nand_to_mtd(chip);
 nsmtd->priv = (void *)chip;
nand= (struct nandsim *)(chip + 1);
chip->priv  = (void *)nand;
@@ -2392,7 +2392,7 @@ err_exit:
for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i)
kfree(nand->partitions[i].name);
 error:
-   kfree(nsmtd);
+   kfree(chip);
free_lists();
 
return retval;
@@ -2413,7 +2413,7 @@ static void __exit ns_cleanup_module(void)
nand_release(nsmtd); /* Unregister driver */
for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i)
kfree(ns->partitions[i].name);
-   kfree(nsmtd);/* Free other structures */
+   kfree(mtd_to_nand(nsmtd));/* Free other structures */
free_lists();
 }
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: gdm72xx: add userspace data struct

2015-12-10 Thread Wim de With
On 10-12-2015 10:37, Dan Carpenter wrote:
> On Thu, Dec 10, 2015 at 10:11:12AM +0100, Wim de With wrote:
>> @@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, 
>> struct ifreq *ifr, int cmd)
>>  /* NOTE: gdm_update_fsm should be called
>>   * before gdm_wimax_ioctl_set_data is called.
>>   */
>> -gdm_update_fsm(dev,
>> -   req->data.buf);
>> +fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
>> +if (!fsm_buf)
>> +return -ENOMEM;
>> +if (copy_from_user(fsm_buf, req->data.buf,
>> +   sizeof(fsm_s))) {
>> +kfree(fsm_buf);
>> +return -EFAULT;
>> +}
>> +gdm_update_fsm(dev, fsm_buf);
>> +kfree(fsm_buf);
> 
> 
> No.  This change is a bug.
> 
> regards,
> dan carpenter
> 

But what if I just keep it as:

gdm_update_fsm(dev, req->data.buf)

Then it would just trust a __user pointer right?

Wim
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 50/58] mtd: nand: remove useless mtd->priv = chip assignments

2015-12-10 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon 
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 drivers/mtd/nand/ams-delta.c   | 3 ---
 drivers/mtd/nand/atmel_nand.c  | 1 -
 drivers/mtd/nand/au1550nd.c| 1 -
 drivers/mtd/nand/bcm47xxnflash/main.c  | 1 -
 drivers/mtd/nand/bf5xx_nand.c  | 1 -
 drivers/mtd/nand/brcmnand/brcmnand.c   | 1 -
 drivers/mtd/nand/cafe_nand.c   | 1 -
 drivers/mtd/nand/cmx270_nand.c | 1 -
 drivers/mtd/nand/cs553x_nand.c | 1 -
 drivers/mtd/nand/davinci_nand.c| 1 -
 drivers/mtd/nand/denali.c  | 1 -
 drivers/mtd/nand/diskonchip.c  | 1 -
 drivers/mtd/nand/docg4.c   | 1 -
 drivers/mtd/nand/fsl_elbc_nand.c   | 1 -
 drivers/mtd/nand/fsl_ifc_nand.c| 1 -
 drivers/mtd/nand/fsl_upm.c | 1 -
 drivers/mtd/nand/fsmc_nand.c   | 1 -
 drivers/mtd/nand/gpio.c| 1 -
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 1 -
 drivers/mtd/nand/hisi504_nand.c| 1 -
 drivers/mtd/nand/jz4740_nand.c | 1 -
 drivers/mtd/nand/lpc32xx_mlc.c | 1 -
 drivers/mtd/nand/lpc32xx_slc.c | 1 -
 drivers/mtd/nand/mpc5121_nfc.c | 1 -
 drivers/mtd/nand/mxc_nand.c| 1 -
 drivers/mtd/nand/nandsim.c | 1 -
 drivers/mtd/nand/ndfc.c| 1 -
 drivers/mtd/nand/nuc900_nand.c | 1 -
 drivers/mtd/nand/omap2.c   | 1 -
 drivers/mtd/nand/orion_nand.c  | 1 -
 drivers/mtd/nand/pasemi_nand.c | 1 -
 drivers/mtd/nand/plat_nand.c   | 1 -
 drivers/mtd/nand/pxa3xx_nand.c | 1 -
 drivers/mtd/nand/r852.c| 1 -
 drivers/mtd/nand/s3c2410.c | 2 --
 drivers/mtd/nand/sh_flctl.c| 1 -
 drivers/mtd/nand/sharpsl.c | 1 -
 drivers/mtd/nand/socrates_nand.c   | 1 -
 drivers/mtd/nand/sunxi_nand.c  | 1 -
 drivers/mtd/nand/tmio_nand.c   | 1 -
 drivers/mtd/nand/txx9ndfmc.c   | 2 --
 drivers/mtd/nand/vf610_nfc.c   | 1 -
 42 files changed, 46 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 0f638c6..1a18938 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -193,9 +193,6 @@ static int ams_delta_init(struct platform_device *pdev)
ams_delta_mtd = nand_to_mtd(this);
ams_delta_mtd->owner = THIS_MODULE;
 
-   /* Link the private data with the MTD structure */
-   ams_delta_mtd->priv = this;
-
/*
 * Don't try to request the memory region from here,
 * it should have been already requested from the
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 9ba2831..18c4e14 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -2128,7 +2128,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
}
 
nand_chip->priv = host; /* link the private data structures */
-   mtd->priv = nand_chip;
mtd->dev.parent = >dev;
 
/* Set address of NAND IO lines */
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 280e5b6..341ea49 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -441,7 +441,6 @@ static int au1550nd_probe(struct platform_device *pdev)
 
this = >chip;
mtd = nand_to_mtd(this);
-   mtd->priv = this;
mtd->dev.parent = >dev;
 
/* figure out which CS# r->start belongs to */
diff --git a/drivers/mtd/nand/bcm47xxnflash/main.c 
b/drivers/mtd/nand/bcm47xxnflash/main.c
index 4711ca2b..0f0a798 100644
--- a/drivers/mtd/nand/bcm47xxnflash/main.c
+++ b/drivers/mtd/nand/bcm47xxnflash/main.c
@@ -37,7 +37,6 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
b47n->nand_chip.priv = b47n;
mtd = nand_to_mtd(>nand_chip);
mtd->dev.parent = >dev;
-   mtd->priv = >nand_chip; /* Required */
b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
 
if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 928d599..9514e13 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -782,7 +782,6 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->chip_delay   = 0;
 
/* initialise mtd info data struct */
-   mtd->priv   = chip;
mtd->dev.parent = >dev;
 
/* initialise the hardware */
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
b/drivers/mtd/nand/brcmnand/brcmnand.c

[PATCH v4 49/58] mtd: nand: update mtd_to_nand()

2015-12-10 Thread Boris Brezillon
Now that all drivers are using the mtd instance embedded in the nand_chip
struct we can safely update the mtd_to_nand() implementation to use
the container_of macro instead of returning the content of mtd->priv.
This will allow us to remove mtd->priv = chip assignments done in all
NAND controller drivers.

Signed-off-by: Boris Brezillon 
---
 include/linux/mtd/nand.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index b614ed2..9cb7ace 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -734,7 +734,7 @@ static inline struct device_node 
*nand_get_flash_node(struct nand_chip *chip)
 
 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
 {
-   return mtd->priv;
+   return container_of(mtd, struct nand_chip, mtd);
 }
 
 static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 46/58] mtd: nand: update the documentation to reflect framework changes

2015-12-10 Thread Boris Brezillon
The MTD device is now directly embedded in the nand_chip struct. Update the
mtdnand documentation to mention this aspect and fix the different
examples.

Signed-off-by: Boris Brezillon 
---
 Documentation/DocBook/mtdnand.tmpl | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/Documentation/DocBook/mtdnand.tmpl 
b/Documentation/DocBook/mtdnand.tmpl
index 403a7ab..b442921 100644
--- a/Documentation/DocBook/mtdnand.tmpl
+++ b/Documentation/DocBook/mtdnand.tmpl
@@ -162,12 +162,15 @@

Basic defines

-   At least you have to provide a mtd structure and
-   a storage for the ioremap'ed chip address.
-   You can allocate the mtd structure using kmalloc
-   or you can allocate it statically.
-   In case of static allocation you have to allocate
-   a nand_chip structure too.
+   At least you have to provide a nand_chip structure
+   and a storage for the ioremap'ed chip address.
+   You can allocate the nand_chip structure using
+   kmalloc or you can allocate it statically.
+   The NAND chip structure embeds an mtd structure
+   which will be registered to the MTD subsystem.
+   You can extract a pointer to the mtd structure
+   from a nand_chip pointer using the nand_to_mtd()
+   helper.


Kmalloc based example
@@ -180,7 +183,6 @@ static void __iomem *baseaddr;
Static example


-static struct mtd_info board_mtd;
 static struct nand_chip board_chip;
 static void __iomem *baseaddr;

@@ -274,13 +276,15 @@ static int __init board_init (void)
int err = 0;
 
/* Allocate memory for MTD device structure and private data */
-   board_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), 
GFP_KERNEL);
-   if (!board_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
printk ("Unable to allocate NAND MTD device structure.\n");
err = -ENOMEM;
goto out;
}
 
+   board_mtd = nand_to_mtd(this);
+
/* map physical address */
baseaddr = ioremap(CHIP_PHYSICAL_ADDRESS, 1024);
if (!baseaddr) {
@@ -289,11 +293,6 @@ static int __init board_init (void)
goto out_mtd;
}
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *) ();
-   /* Link the private data with the MTD structure */
-   board_mtd->priv = this;
-
/* Set address of NAND IO lines */
this->IO_ADDR_R = baseaddr;
this->IO_ADDR_W = baseaddr;
@@ -317,7 +316,7 @@ static int __init board_init (void)
 out_ior:
iounmap(baseaddr);
 out_mtd:
-   kfree (board_mtd);
+   kfree (this);
 out:
return err;
 }
@@ -343,7 +342,7 @@ static void __exit board_cleanup (void)
iounmap(baseaddr);

/* Free the MTD device structure */
-   kfree (board_mtd);
+   kfree (mtd_to_nand(board_mtd));
 }
 module_exit(board_cleanup);
 #endif
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 47/58] staging: mt29f_spinand: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device, use it instead of allocating
a new one.

Signed-off-by: Boris Brezillon 
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 8924a96..8171b74 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -903,9 +903,7 @@ static int spinand_probe(struct spi_device *spi_nand)
chip->options   |= NAND_CACHEPRG;
chip->select_chip = spinand_select_chip;
 
-   mtd = devm_kzalloc(_nand->dev, sizeof(struct mtd_info), GFP_KERNEL);
-   if (!mtd)
-   return -ENOMEM;
+   mtd = nand_to_mtd(chip);
 
dev_set_drvdata(_nand->dev, mtd);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 48/58] cris: nand: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Patch all drivers to make use
of this mtd instance instead of using the instance embedded in their
private struct or dynamically allocated.

Signed-off-by: Boris Brezillon 
---
Most of those changes were generated with the coccinelle script added
in commit c671312 "coccinelle: nand: detect and correct drivers embedding
an mtd_info object"
---
 arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 3 +--
 arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
index db953cf..ee74e45 100644
--- a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
@@ -36,7 +36,6 @@
 #define CE_BIT 12
 
 struct mtd_info_wrapper {
-   struct mtd_info info;
struct nand_chip chip;
 };
 
@@ -148,7 +147,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
 
/* Get pointer to private data */
this = >chip;
-   crisv32_mtd = >info;
+   crisv32_mtd = nand_to_mtd(this);
 
/* Link the private data with the MTD structure */
crisv32_mtd->priv = this;
diff --git a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
index 22a6467..5626297 100644
--- a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
@@ -31,7 +31,6 @@
 #define BY_BIT 7
 
 struct mtd_info_wrapper {
-   struct mtd_info info;
struct nand_chip chip;
 };
 
@@ -129,7 +128,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
 
/* Get pointer to private data */
this = >chip;
-   crisv32_mtd = >info;
+   crisv32_mtd = nand_to_mtd(this);
 
pa_oe.oe |= 1 << CE_BIT;
pa_oe.oe |= 1 << ALE_BIT;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 44/58] mtd: nand: txx9ndfmc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/txx9ndfmc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c
index ff9afb1..da7fcbd 100644
--- a/drivers/mtd/nand/txx9ndfmc.c
+++ b/drivers/mtd/nand/txx9ndfmc.c
@@ -63,7 +63,6 @@
 struct txx9ndfmc_priv {
struct platform_device *dev;
struct nand_chip chip;
-   struct mtd_info mtd;
int cs;
const char *mtdname;
 };
@@ -322,7 +321,7 @@ static int __init txx9ndfmc_probe(struct platform_device 
*dev)
if (!txx9_priv)
continue;
chip = _priv->chip;
-   mtd = _priv->mtd;
+   mtd = nand_to_mtd(chip);
mtd->dev.parent = >dev;
 
mtd->priv = chip;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 45/58] mtd: nand: vf610: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/vf610_nfc.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 1c86c6b..1bbb93a 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -156,7 +156,6 @@ enum vf610_nfc_variant {
 };
 
 struct vf610_nfc {
-   struct mtd_info mtd;
struct nand_chip chip;
struct device *dev;
void __iomem *regs;
@@ -171,7 +170,10 @@ struct vf610_nfc {
u32 ecc_mode;
 };
 
-#define mtd_to_nfc(_mtd) container_of(_mtd, struct vf610_nfc, mtd)
+static inline struct vf610_nfc *mtd_to_nfc(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct vf610_nfc, chip);
+}
 
 static struct nand_ecclayout vf610_nfc_ecc45 = {
.eccbytes = 45,
@@ -674,8 +676,8 @@ static int vf610_nfc_probe(struct platform_device *pdev)
return -ENOMEM;
 
nfc->dev = >dev;
-   mtd = >mtd;
chip = >chip;
+   mtd = nand_to_mtd(chip);
 
mtd->priv = chip;
mtd->owner = THIS_MODULE;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 05/58] mtd: nand: ams-delta: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance
instead of allocating our own.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/ams-delta.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index b2b49c4..0f638c6 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -183,19 +183,16 @@ static int ams_delta_init(struct platform_device *pdev)
return -ENXIO;
 
/* Allocate memory for MTD device structure and private data */
-   ams_delta_mtd = kzalloc(sizeof(struct mtd_info) +
-   sizeof(struct nand_chip), GFP_KERNEL);
-   if (!ams_delta_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
printk (KERN_WARNING "Unable to allocate E3 NAND MTD device 
structure.\n");
err = -ENOMEM;
goto out;
}
 
+   ams_delta_mtd = nand_to_mtd(this);
ams_delta_mtd->owner = THIS_MODULE;
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *) (_delta_mtd[1]);
-
/* Link the private data with the MTD structure */
ams_delta_mtd->priv = this;
 
@@ -256,7 +253,7 @@ out_gpio:
gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB);
iounmap(io_base);
 out_free:
-   kfree(ams_delta_mtd);
+   kfree(this);
  out:
return err;
 }
@@ -276,7 +273,7 @@ static int ams_delta_cleanup(struct platform_device *pdev)
iounmap(io_base);
 
/* Free the MTD device structure */
-   kfree(ams_delta_mtd);
+   kfree(mtd_to_nand(ams_delta_mtd));
 
return 0;
 }
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 03/58] mtd: nand: nuc900: create and use mtd_to_nuc900()

2015-12-10 Thread Boris Brezillon
Create and use mtd_to_nuc900() instead of direct container_of() calls.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/nuc900_nand.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c
index 8148cd6..65908c0 100644
--- a/drivers/mtd/nand/nuc900_nand.c
+++ b/drivers/mtd/nand/nuc900_nand.c
@@ -62,6 +62,11 @@ struct nuc900_nand {
spinlock_t lock;
 };
 
+static inline struct nuc900_nand *mtd_to_nuc900(struct mtd_info *mtd)
+{
+   return container_of(mtd, struct nuc900_nand, mtd);
+}
+
 static const struct mtd_partition partitions[] = {
{
 .name = "NAND FS 0",
@@ -78,9 +83,7 @@ static const struct mtd_partition partitions[] = {
 static unsigned char nuc900_nand_read_byte(struct mtd_info *mtd)
 {
unsigned char ret;
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
ret = (unsigned char)read_data_reg(nand);
 
@@ -91,9 +94,7 @@ static void nuc900_nand_read_buf(struct mtd_info *mtd,
 unsigned char *buf, int len)
 {
int i;
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
for (i = 0; i < len; i++)
buf[i] = (unsigned char)read_data_reg(nand);
@@ -103,9 +104,7 @@ static void nuc900_nand_write_buf(struct mtd_info *mtd,
  const unsigned char *buf, int len)
 {
int i;
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
for (i = 0; i < len; i++)
write_data_reg(nand, buf[i]);
@@ -124,11 +123,9 @@ static int nuc900_check_rb(struct nuc900_nand *nand)
 
 static int nuc900_nand_devready(struct mtd_info *mtd)
 {
-   struct nuc900_nand *nand;
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
int ready;
 
-   nand = container_of(mtd, struct nuc900_nand, mtd);
-
ready = (nuc900_check_rb(nand)) ? 1 : 0;
return ready;
 }
@@ -137,9 +134,7 @@ static void nuc900_nand_command_lp(struct mtd_info *mtd, 
unsigned int command,
   int column, int page_addr)
 {
register struct nand_chip *chip = mtd_to_nand(mtd);
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
if (command == NAND_CMD_READOOB) {
column += mtd->writesize;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 06/58] mtd: nand: atmel: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/atmel_nand.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index edd191a..9ba2831 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -116,7 +116,6 @@ static struct atmel_nfc nand_nfc;
 
 struct atmel_nand_host {
struct nand_chipnand_chip;
-   struct mtd_info mtd;
void __iomem*io_base;
dma_addr_t  io_phys;
struct atmel_nand_data  board;
@@ -317,8 +316,10 @@ static int nfc_set_sram_bank(struct atmel_nand_host *host, 
unsigned int bank)
return -EINVAL;
 
if (bank) {
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
+
/* Only for a 2k-page or lower flash, NFC can handle 2 banks */
-   if (host->mtd.writesize > 2048)
+   if (mtd->writesize > 2048)
return -EINVAL;
nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1);
} else {
@@ -1159,8 +1160,8 @@ static uint16_t *create_lookup_table(struct device *dev, 
int sector_size)
 static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
 struct atmel_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
struct nand_chip *nand_chip = >nand_chip;
+   struct mtd_info *mtd = nand_to_mtd(nand_chip);
struct resource *regs, *regs_pmerr, *regs_rom;
uint16_t *galois_table;
int cap, sector_size, err_no;
@@ -1586,8 +1587,8 @@ static int atmel_of_init_port(struct atmel_nand_host 
*host,
 static int atmel_hw_nand_init_params(struct platform_device *pdev,
 struct atmel_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
struct nand_chip *nand_chip = >nand_chip;
+   struct mtd_info *mtd = nand_to_mtd(nand_chip);
struct resource *regs;
 
regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -2112,8 +2113,8 @@ static int atmel_nand_probe(struct platform_device *pdev)
}
host->io_phys = (dma_addr_t)mem->start;
 
-   mtd = >mtd;
nand_chip = >nand_chip;
+   mtd = nand_to_mtd(nand_chip);
host->dev = >dev;
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
nand_set_flash_node(nand_chip, pdev->dev.of_node);
@@ -2283,7 +2284,7 @@ err_nand_ioremap:
 static int atmel_nand_remove(struct platform_device *pdev)
 {
struct atmel_nand_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-10 Thread Boris Brezillon
Unregister the NAND device from the NAND subsystem when removing a denali
NAND controller, otherwise the MTD attached to the NAND device is still
exposed by the MTD layer, and accesses to this device will likely crash
the system.

Signed-off-by: Boris Brezillon 
Cc:  #3.8+
Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")
---
 drivers/mtd/nand/denali.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 67eb2be..8feece3 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1622,6 +1622,7 @@ EXPORT_SYMBOL(denali_init);
 /* driver exit point */
 void denali_remove(struct denali_nand_info *denali)
 {
+   nand_release(>mtd);
denali_irq_cleanup(denali->irq, denali);
dma_unmap_single(denali->dev, denali->buf.dma_buf,
 denali->mtd.writesize + denali->mtd.oobsize,
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 33/58] mtd: nand: orion: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/orion_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 4ed4f67..087a040 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -85,11 +85,11 @@ static int __init orion_nand_probe(struct platform_device 
*pdev)
u32 val = 0;
 
nc = devm_kzalloc(>dev,
-   sizeof(struct nand_chip) + sizeof(struct mtd_info),
+   sizeof(struct nand_chip),
GFP_KERNEL);
if (!nc)
return -ENOMEM;
-   mtd = (struct mtd_info *)(nc + 1);
+   mtd = nand_to_mtd(nc);
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
io_base = devm_ioremap_resource(>dev, res);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 34/58] mtd: nand: pasemi: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/pasemi_nand.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index 0ececac..4dd2985 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -110,17 +110,15 @@ static int pasemi_nand_probe(struct platform_device 
*ofdev)
pr_debug("pasemi_nand at %pR\n", );
 
/* Allocate memory for MTD device structure and private data */
-   pasemi_nand_mtd = kzalloc(sizeof(struct mtd_info) +
- sizeof(struct nand_chip), GFP_KERNEL);
-   if (!pasemi_nand_mtd) {
+   chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!chip) {
printk(KERN_WARNING
   "Unable to allocate PASEMI NAND MTD device structure\n");
err = -ENOMEM;
goto out;
}
 
-   /* Get pointer to private data */
-   chip = (struct nand_chip *)_nand_mtd[1];
+   pasemi_nand_mtd = nand_to_mtd(chip);
 
/* Link the private data with the MTD structure */
pasemi_nand_mtd->priv = chip;
@@ -180,7 +178,7 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
  out_ior:
iounmap(chip->IO_ADDR_R);
  out_mtd:
-   kfree(pasemi_nand_mtd);
+   kfree(chip);
  out:
return err;
 }
@@ -202,7 +200,7 @@ static int pasemi_nand_remove(struct platform_device *ofdev)
iounmap(chip->IO_ADDR_R);
 
/* Free the MTD device structure */
-   kfree(pasemi_nand_mtd);
+   kfree(chip);
 
pasemi_nand_mtd = NULL;
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 37/58] mtd: nand: r852: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/r852.c | 34 +++---
 drivers/mtd/nand/r852.h |  1 -
 2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c
index ca05b20..1ac8ef2 100644
--- a/drivers/mtd/nand/r852.c
+++ b/drivers/mtd/nand/r852.c
@@ -634,25 +634,22 @@ static void r852_update_media_status(struct r852_device 
*dev)
  */
 static int r852_register_nand_device(struct r852_device *dev)
 {
-   dev->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
-
-   if (!dev->mtd)
-   goto error1;
+   struct mtd_info *mtd = nand_to_mtd(dev->chip);
 
WARN_ON(dev->card_registred);
 
-   dev->mtd->priv = dev->chip;
-   dev->mtd->dev.parent = >pci_dev->dev;
+   mtd->priv = dev->chip;
+   mtd->dev.parent = >pci_dev->dev;
 
if (dev->readonly)
dev->chip->options |= NAND_ROM;
 
r852_engine_enable(dev);
 
-   if (sm_register_device(dev->mtd, dev->sm))
-   goto error2;
+   if (sm_register_device(mtd, dev->sm))
+   goto error1;
 
-   if (device_create_file(>mtd->dev, _attr_media_type)) {
+   if (device_create_file(>dev, _attr_media_type)) {
message("can't create media type sysfs attribute");
goto error3;
}
@@ -660,9 +657,7 @@ static int r852_register_nand_device(struct r852_device 
*dev)
dev->card_registred = 1;
return 0;
 error3:
-   nand_release(dev->mtd);
-error2:
-   kfree(dev->mtd);
+   nand_release(mtd);
 error1:
/* Force card redetect */
dev->card_detected = 0;
@@ -675,15 +670,15 @@ error1:
 
 static void r852_unregister_nand_device(struct r852_device *dev)
 {
+   struct mtd_info *mtd = nand_to_mtd(dev->chip);
+
if (!dev->card_registred)
return;
 
-   device_remove_file(>mtd->dev, _attr_media_type);
-   nand_release(dev->mtd);
+   device_remove_file(>dev, _attr_media_type);
+   nand_release(mtd);
r852_engine_disable(dev);
dev->card_registred = 0;
-   kfree(dev->mtd);
-   dev->mtd = NULL;
 }
 
 /* Card state updater */
@@ -1031,6 +1026,7 @@ static int r852_suspend(struct device *device)
 static int r852_resume(struct device *device)
 {
struct r852_device *dev = pci_get_drvdata(to_pci_dev(device));
+   struct mtd_info *mtd = nand_to_mtd(dev->chip);
 
r852_disable_irqs(dev);
r852_card_update_present(dev);
@@ -1050,9 +1046,9 @@ static int r852_resume(struct device *device)
/* Otherwise, initialize the card */
if (dev->card_registred) {
r852_engine_enable(dev);
-   dev->chip->select_chip(dev->mtd, 0);
-   dev->chip->cmdfunc(dev->mtd, NAND_CMD_RESET, -1, -1);
-   dev->chip->select_chip(dev->mtd, -1);
+   dev->chip->select_chip(mtd, 0);
+   dev->chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+   dev->chip->select_chip(mtd, -1);
}
 
/* Program card detection IRQ */
diff --git a/drivers/mtd/nand/r852.h b/drivers/mtd/nand/r852.h
index e6a21d9..d042ddb 100644
--- a/drivers/mtd/nand/r852.h
+++ b/drivers/mtd/nand/r852.h
@@ -108,7 +108,6 @@
 
 struct r852_device {
void __iomem *mmio; /* mmio */
-   struct mtd_info *mtd;   /* mtd backpointer */
struct nand_chip *chip; /* nand chip backpointer */
struct pci_dev *pci_dev;/* pci backpointer */
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 15/58] mtd: nand: denali: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---

Conflicts:
drivers/mtd/nand/denali.c
---
 drivers/mtd/nand/denali.c | 70 ++-
 drivers/mtd/nand/denali.h |  1 -
 2 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 8feece3..2b66cee 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -75,7 +75,10 @@ MODULE_PARM_DESC(onfi_timing_mode,
  * this macro allows us to convert from an MTD structure to our own
  * device context (denali) structure.
  */
-#define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd)
+static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
+}
 
 /*
  * These constants are defined by the driver to enable common driver
@@ -986,6 +989,8 @@ static bool handle_ecc(struct denali_nand_info *denali, 
uint8_t *buf,
 * than one NAND connected.
 */
if (err_byte < ECC_SECTOR_SIZE) {
+   struct mtd_info *mtd =
+   nand_to_mtd(>nand);
int offset;
 
offset = (err_sector *
@@ -995,7 +1000,7 @@ static bool handle_ecc(struct denali_nand_info *denali, 
uint8_t *buf,
err_device;
/* correct the ECC error */
buf[offset] ^= err_correction_value;
-   denali->mtd.ecc_stats.corrected++;
+   mtd->ecc_stats.corrected++;
bitflips++;
}
} else {
@@ -1062,7 +1067,7 @@ static int write_page(struct mtd_info *mtd, struct 
nand_chip *chip,
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
dma_addr_t addr = denali->buf.dma_buf;
-   size_t size = denali->mtd.writesize + denali->mtd.oobsize;
+   size_t size = mtd->writesize + mtd->oobsize;
uint32_t irq_status;
uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
INTR_STATUS__PROGRAM_FAIL;
@@ -1160,7 +1165,7 @@ static int denali_read_page(struct mtd_info *mtd, struct 
nand_chip *chip,
struct denali_nand_info *denali = mtd_to_denali(mtd);
 
dma_addr_t addr = denali->buf.dma_buf;
-   size_t size = denali->mtd.writesize + denali->mtd.oobsize;
+   size_t size = mtd->writesize + mtd->oobsize;
 
uint32_t irq_status;
uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
@@ -1193,14 +1198,14 @@ static int denali_read_page(struct mtd_info *mtd, 
struct nand_chip *chip,
denali_enable_dma(denali, false);
 
if (check_erased_page) {
-   read_oob_data(>mtd, chip->oob_poi, denali->page);
+   read_oob_data(mtd, chip->oob_poi, denali->page);
 
/* check ECC failures that may have occurred on erased pages */
if (check_erased_page) {
-   if (!is_erased(buf, denali->mtd.writesize))
-   denali->mtd.ecc_stats.failed++;
-   if (!is_erased(buf, denali->mtd.oobsize))
-   denali->mtd.ecc_stats.failed++;
+   if (!is_erased(buf, mtd->writesize))
+   mtd->ecc_stats.failed++;
+   if (!is_erased(buf, mtd->oobsize))
+   mtd->ecc_stats.failed++;
}
}
return max_bitflips;
@@ -1211,7 +1216,7 @@ static int denali_read_page_raw(struct mtd_info *mtd, 
struct nand_chip *chip,
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
dma_addr_t addr = denali->buf.dma_buf;
-   size_t 

[PATCH v4 18/58] mtd: nand: fsl_elbc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsl_elbc_nand.c | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index ad6d5da..7bde76a 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -48,7 +48,6 @@
 /* mtd information per set */
 
 struct fsl_elbc_mtd {
-   struct mtd_info mtd;
struct nand_chip chip;
struct fsl_lbc_ctrl *ctrl;
 
@@ -742,12 +741,13 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
struct fsl_lbc_regs __iomem *lbc = ctrl->regs;
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
dev_dbg(priv->dev, "eLBC Set Information for bank %d\n", priv->bank);
 
/* Fill in fsl_elbc_mtd structure */
-   priv->mtd.priv = chip;
-   priv->mtd.dev.parent = priv->dev;
+   mtd->priv = chip;
+   mtd->dev.parent = priv->dev;
nand_set_flash_node(chip, priv->dev->of_node);
 
/* set timeout to maximum */
@@ -798,9 +798,11 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
 {
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
-   nand_release(>mtd);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
-   kfree(priv->mtd.name);
+   nand_release(mtd);
+
+   kfree(mtd->name);
 
if (priv->vbase)
iounmap(priv->vbase);
@@ -824,6 +826,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
int bank;
struct device *dev;
struct device_node *node = pdev->dev.of_node;
+   struct mtd_info *mtd;
 
if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)
return -ENODEV;
@@ -886,8 +889,9 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
goto err;
}
 
-   priv->mtd.name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
-   if (!priv->mtd.name) {
+   mtd = nand_to_mtd(>chip);
+   mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
+   if (!nand_to_mtd(>chip)->name) {
ret = -ENOMEM;
goto err;
}
@@ -896,21 +900,21 @@ static int fsl_elbc_nand_probe(struct platform_device 
*pdev)
if (ret)
goto err;
 
-   ret = nand_scan_ident(>mtd, 1, NULL);
+   ret = nand_scan_ident(mtd, 1, NULL);
if (ret)
goto err;
 
-   ret = fsl_elbc_chip_init_tail(>mtd);
+   ret = fsl_elbc_chip_init_tail(mtd);
if (ret)
goto err;
 
-   ret = nand_scan_tail(>mtd);
+   ret = nand_scan_tail(mtd);
if (ret)
goto err;
 
/* First look for RedBoot table or partitions on the command
 * line, these take precedence over device tree information */
-   mtd_device_parse_register(>mtd, part_probe_types, NULL,
+   mtd_device_parse_register(mtd, part_probe_types, NULL,
  NULL, 0);
 
printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 09/58] mtd: nand: bf5xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/bf5xx_nand.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index d9da5ed..928d599 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -142,7 +142,6 @@ static struct nand_ecclayout bootrom_ecclayout = {
 struct bf5xx_nand_info {
/* mtd info */
struct nand_hw_control  controller;
-   struct mtd_info mtd;
struct nand_chipchip;
 
/* platform info */
@@ -160,7 +159,8 @@ struct bf5xx_nand_info {
  */
 static struct bf5xx_nand_info *mtd_to_nand_info(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct bf5xx_nand_info, mtd);
+   return container_of(mtd_to_nand(mtd), struct bf5xx_nand_info,
+   chip);
 }
 
 static struct bf5xx_nand_info *to_nand_info(struct platform_device *pdev)
@@ -660,7 +660,7 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
  */
 static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct mtd_partition *parts = info->platform->partitions;
int nr = info->platform->nr_partitions;
 
@@ -675,7 +675,7 @@ static int bf5xx_nand_remove(struct platform_device *pdev)
 * and their partitions, then go through freeing the
 * resources used
 */
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
peripheral_free_list(bfin_nfc_pin_req);
bf5xx_nand_dma_remove(info);
@@ -756,6 +756,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
 
/* initialise chip data struct */
chip = >chip;
+   mtd = nand_to_mtd(>chip);
 
if (plat->data_width)
chip->options |= NAND_BUSWIDTH_16;
@@ -772,7 +773,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->cmd_ctrl = bf5xx_nand_hwcontrol;
chip->dev_ready= bf5xx_nand_devready;
 
-   chip->priv = >mtd;
+   chip->priv = mtd;
chip->controller   = >controller;
 
chip->IO_ADDR_R= (void __iomem *) NFC_READ;
@@ -781,7 +782,6 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->chip_delay   = 0;
 
/* initialise mtd info data struct */
-   mtd = >mtd;
mtd->priv   = chip;
mtd->dev.parent = >dev;
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 08/58] mtd: nand: bcm47xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h | 1 -
 drivers/mtd/nand/bcm47xxnflash/main.c  | 8 +---
 drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c   | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h 
b/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
index c005a62..8ea7571 100644
--- a/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
+++ b/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
@@ -12,7 +12,6 @@ struct bcm47xxnflash {
struct bcma_drv_cc *cc;
 
struct nand_chip nand_chip;
-   struct mtd_info mtd;
 
unsigned curr_command;
int curr_page_addr;
diff --git a/drivers/mtd/nand/bcm47xxnflash/main.c 
b/drivers/mtd/nand/bcm47xxnflash/main.c
index 9ba0c0f..4711ca2b 100644
--- a/drivers/mtd/nand/bcm47xxnflash/main.c
+++ b/drivers/mtd/nand/bcm47xxnflash/main.c
@@ -27,6 +27,7 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
 {
struct bcma_nflash *nflash = dev_get_platdata(>dev);
struct bcm47xxnflash *b47n;
+   struct mtd_info *mtd;
int err = 0;
 
b47n = devm_kzalloc(>dev, sizeof(*b47n), GFP_KERNEL);
@@ -34,8 +35,9 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
return -ENOMEM;
 
b47n->nand_chip.priv = b47n;
-   b47n->mtd.dev.parent = >dev;
-   b47n->mtd.priv = >nand_chip; /* Required */
+   mtd = nand_to_mtd(>nand_chip);
+   mtd->dev.parent = >dev;
+   mtd->priv = >nand_chip; /* Required */
b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
 
if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
@@ -49,7 +51,7 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
return err;
}
 
-   err = mtd_device_parse_register(>mtd, probes, NULL, NULL, 0);
+   err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
if (err) {
pr_err("Failed to register MTD device: %d\n", err);
return err;
diff --git a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c 
b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
index e5b2e48..6524780 100644
--- a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
+++ b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
@@ -421,7 +421,7 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash 
*b47n)
(w4 << 24 | w3 << 18 | w2 << 12 | w1 << 6 | w0));
 
/* Scan NAND */
-   err = nand_scan(>mtd, 1);
+   err = nand_scan(nand_to_mtd(>nand_chip), 1);
if (err) {
pr_err("Could not scan NAND flash: %d\n", err);
goto exit;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 04/58] mtd: nand: omap2: create and use mtd_to_omap()

2015-12-10 Thread Boris Brezillon
Define and use mtd_to_omap() instead of container_of();

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/omap2.c | 55 ++--
 1 file changed, 21 insertions(+), 34 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 944a74e..1fb40db 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -177,6 +177,10 @@ struct omap_nand_info {
struct device_node  *of_node;
 };
 
+static inline struct omap_nand_info *mtd_to_omap(struct mtd_info *mtd)
+{
+   return container_of(mtd, struct omap_nand_info, mtd);
+}
 /**
  * omap_prefetch_enable - configures and starts prefetch transfer
  * @cs: cs (chip select) number
@@ -247,8 +251,7 @@ static int omap_prefetch_reset(int cs, struct 
omap_nand_info *info)
  */
 static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
 
if (cmd != NAND_CMD_NONE) {
if (ctrl & NAND_CLE)
@@ -283,8 +286,7 @@ static void omap_read_buf8(struct mtd_info *mtd, u_char 
*buf, int len)
  */
 static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
u_char *p = (u_char *)buf;
u32 status = 0;
 
@@ -319,8 +321,7 @@ static void omap_read_buf16(struct mtd_info *mtd, u_char 
*buf, int len)
  */
 static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
u16 *p = (u16 *) buf;
u32 status = 0;
/* FIXME try bursts of writesw() or DMA ... */
@@ -344,8 +345,7 @@ static void omap_write_buf16(struct mtd_info *mtd, const 
u_char * buf, int len)
  */
 static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
uint32_t r_count = 0;
int ret = 0;
u32 *p = (u32 *)buf;
@@ -392,8 +392,7 @@ static void omap_read_buf_pref(struct mtd_info *mtd, u_char 
*buf, int len)
 static void omap_write_buf_pref(struct mtd_info *mtd,
const u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
uint32_t w_count = 0;
int i = 0, ret = 0;
u16 *p = (u16 *)buf;
@@ -458,8 +457,7 @@ static void omap_nand_dma_callback(void *data)
 static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
unsigned int len, int is_write)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
struct dma_async_tx_descriptor *tx;
enum dma_data_direction dir = is_write ? DMA_TO_DEVICE :
DMA_FROM_DEVICE;
@@ -623,8 +621,7 @@ done:
  */
 static void omap_read_buf_irq_pref(struct mtd_info *mtd, u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
int ret = 0;
 
if (len <= mtd->oobsize) {
@@ -671,8 +668,7 @@ out_copy:
 static void omap_write_buf_irq_pref(struct mtd_info *mtd,
const u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
int ret = 0;
unsigned long tim, limit;
u32 val;
@@ -886,8 +882,7 @@ static int omap_compare_ecc(u8 *ecc_data1,  /* read from 
NAND memory */
 static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
u_char *read_ecc, u_char *calc_ecc)
 {
-   struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
-   mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
int blockCnt = 0, i = 0, ret = 0;
int stat = 0;
 
@@ -928,8 +923,7 @@ static int omap_correct_data(struct mtd_info *mtd, u_char 

[PATCH v4 16/58] mtd: nand: diskonchip: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/diskonchip.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 5f7bcc8..fff7a4a 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1556,15 +1556,15 @@ static int __init doc_probe(unsigned long physadr)
 
printk(KERN_NOTICE "DiskOnChip found at 0x%lx\n", physadr);
 
-   len = sizeof(struct mtd_info) +
-   sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * 
sizeof(struct nand_bbt_descr));
-   mtd = kzalloc(len, GFP_KERNEL);
-   if (!mtd) {
+   len = sizeof(struct nand_chip) + sizeof(struct doc_priv) +
+ (2 * sizeof(struct nand_bbt_descr));
+   nand = kzalloc(len, GFP_KERNEL);
+   if (!nand) {
ret = -ENOMEM;
goto fail;
}
 
-   nand= (struct nand_chip *) (mtd + 1);
+   mtd = nand_to_mtd(nand);
doc = (struct doc_priv *) (nand + 1);
nand->bbt_td= (struct nand_bbt_descr *) (doc + 1);
nand->bbt_md= nand->bbt_td + 1;
@@ -1615,7 +1615,7 @@ static int __init doc_probe(unsigned long physadr)
   haven't yet added it.  This is handled without incident by
   mtd_device_unregister, as far as I can tell. */
nand_release(mtd);
-   kfree(mtd);
+   kfree(nand);
goto fail;
}
 
@@ -1650,7 +1650,7 @@ static void release_nanddoc(void)
nand_release(mtd);
iounmap(doc->virtadr);
release_mem_region(doc->physadr, DOC_IOREMAP_LEN);
-   kfree(mtd);
+   kfree(nand);
}
 }
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 19/58] mtd: nand: fsl_ifc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsl_ifc_nand.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index 3136842..3f5654f 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -40,7 +40,6 @@ struct fsl_ifc_ctrl;
 
 /* mtd information per set */
 struct fsl_ifc_mtd {
-   struct mtd_info mtd;
struct nand_chip chip;
struct fsl_ifc_ctrl *ctrl;
 
@@ -877,12 +876,13 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
struct fsl_ifc_ctrl *ctrl = priv->ctrl;
struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct nand_ecclayout *layout;
u32 csor;
 
/* Fill in fsl_ifc_mtd structure */
-   priv->mtd.priv = chip;
-   priv->mtd.dev.parent = priv->dev;
+   mtd->priv = chip;
+   mtd->dev.parent = priv->dev;
nand_set_flash_node(chip, priv->dev->of_node);
 
/* fill in nand_chip structure */
@@ -994,9 +994,11 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
 
 static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)
 {
-   nand_release(>mtd);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
-   kfree(priv->mtd.name);
+   nand_release(mtd);
+
+   kfree(mtd->name);
 
if (priv->vbase)
iounmap(priv->vbase);
@@ -1031,6 +1033,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
int ret;
int bank;
struct device_node *node = dev->dev.of_node;
+   struct mtd_info *mtd;
 
if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)
return -ENODEV;
@@ -1103,8 +1106,10 @@ static int fsl_ifc_nand_probe(struct platform_device 
*dev)
  IFC_NAND_EVTER_INTR_FTOERIR_EN |
  IFC_NAND_EVTER_INTR_WPERIR_EN,
  >ifc_nand.nand_evter_intr_en);
-   priv->mtd.name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
-   if (!priv->mtd.name) {
+
+   mtd = nand_to_mtd(>chip);
+   mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
+   if (!mtd->name) {
ret = -ENOMEM;
goto err;
}
@@ -1113,22 +1118,21 @@ static int fsl_ifc_nand_probe(struct platform_device 
*dev)
if (ret)
goto err;
 
-   ret = nand_scan_ident(>mtd, 1, NULL);
+   ret = nand_scan_ident(mtd, 1, NULL);
if (ret)
goto err;
 
-   ret = fsl_ifc_chip_init_tail(>mtd);
+   ret = fsl_ifc_chip_init_tail(mtd);
if (ret)
goto err;
 
-   ret = nand_scan_tail(>mtd);
+   ret = nand_scan_tail(mtd);
if (ret)
goto err;
 
/* First look for RedBoot table or partitions on the command
 * line, these take precedence over device tree information */
-   mtd_device_parse_register(>mtd, part_probe_types, NULL,
-   NULL, 0);
+   mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
 
dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
 (unsigned long long)res.start, priv->bank);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 20/58] mtd: nand: fsl_upm: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsl_upm.c | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 68ec128..0379adc 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -31,7 +31,6 @@
 
 struct fsl_upm_nand {
struct device *dev;
-   struct mtd_info mtd;
struct nand_chip chip;
int last_ctrl;
struct mtd_partition *parts;
@@ -49,7 +48,8 @@ struct fsl_upm_nand {
 
 static inline struct fsl_upm_nand *to_fsl_upm_nand(struct mtd_info *mtdinfo)
 {
-   return container_of(mtdinfo, struct fsl_upm_nand, mtd);
+   return container_of(mtd_to_nand(mtdinfo), struct fsl_upm_nand,
+   chip);
 }
 
 static int fun_chip_ready(struct mtd_info *mtd)
@@ -66,9 +66,10 @@ static int fun_chip_ready(struct mtd_info *mtd)
 static void fun_wait_rnb(struct fsl_upm_nand *fun)
 {
if (fun->rnb_gpio[fun->mchip_number] >= 0) {
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int cnt = 100;
 
-   while (--cnt && !fun_chip_ready(>mtd))
+   while (--cnt && !fun_chip_ready(mtd))
cpu_relax();
if (!cnt)
dev_err(fun->dev, "tired waiting for RNB\n");
@@ -157,6 +158,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 const struct device_node *upm_np,
 const struct resource *io_res)
 {
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int ret;
struct device_node *flash_np;
 
@@ -174,30 +176,30 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
if (fun->rnb_gpio[0] >= 0)
fun->chip.dev_ready = fun_chip_ready;
 
-   fun->mtd.priv = >chip;
-   fun->mtd.dev.parent = fun->dev;
+   mtd->priv = >chip;
+   mtd->dev.parent = fun->dev;
 
flash_np = of_get_next_child(upm_np, NULL);
if (!flash_np)
return -ENODEV;
 
nand_set_flash_node(>chip, flash_np);
-   fun->mtd.name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
- flash_np->name);
-   if (!fun->mtd.name) {
+   mtd->name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
+ flash_np->name);
+   if (!mtd->name) {
ret = -ENOMEM;
goto err;
}
 
-   ret = nand_scan(>mtd, fun->mchip_count);
+   ret = nand_scan(mtd, fun->mchip_count);
if (ret)
goto err;
 
-   ret = mtd_device_register(>mtd, NULL, 0);
+   ret = mtd_device_register(mtd, NULL, 0);
 err:
of_node_put(flash_np);
if (ret)
-   kfree(fun->mtd.name);
+   kfree(mtd->name);
return ret;
 }
 
@@ -321,10 +323,11 @@ err1:
 static int fun_remove(struct platform_device *ofdev)
 {
struct fsl_upm_nand *fun = dev_get_drvdata(>dev);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int i;
 
-   nand_release(>mtd);
-   kfree(fun->mtd.name);
+   nand_release(mtd);
+   kfree(mtd->name);
 
for (i = 0; i < fun->mchip_count; i++) {
if (fun->rnb_gpio[i] < 0)
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 13/58] mtd: nand: cs553x: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/cs553x_nand.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 8904d68..386ae83 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -197,14 +197,13 @@ static int __init cs553x_init_one(int cs, int mmio, 
unsigned long adr)
}
 
/* Allocate memory for MTD device structure and private data */
-   new_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), 
GFP_KERNEL);
-   if (!new_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
err = -ENOMEM;
goto out;
}
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *)(_mtd[1]);
+   new_mtd = nand_to_mtd(this);
 
/* Link the private data with the MTD structure */
new_mtd->priv = this;
@@ -257,7 +256,7 @@ out_free:
 out_ior:
iounmap(this->IO_ADDR_R);
 out_mtd:
-   kfree(new_mtd);
+   kfree(this);
 out:
return err;
 }
@@ -337,19 +336,19 @@ static void __exit cs553x_cleanup(void)
if (!mtd)
continue;
 
-   this = mtd_to_nand(cs553x_mtd[i]);
+   this = mtd_to_nand(mtd);
mmio_base = this->IO_ADDR_R;
 
/* Release resources, unregister device */
-   nand_release(cs553x_mtd[i]);
-   kfree(cs553x_mtd[i]->name);
+   nand_release(mtd);
+   kfree(mtd->name);
cs553x_mtd[i] = NULL;
 
/* unmap physical address */
iounmap(mmio_base);
 
/* Free the MTD device structure */
-   kfree(mtd);
+   kfree(this);
}
 }
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 23/58] mtd: nand: gpmi: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c  |  2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 23 +++
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h |  1 -
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c 
b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
index 43fa16b..0f68a99 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -919,7 +919,7 @@ static int enable_edo_mode(struct gpmi_nand_data *this, int 
mode)
 {
struct resources  *r = >resources;
struct nand_chip *nand = >nand;
-   struct mtd_info  *mtd = >mtd;
+   struct mtd_info  *mtd = nand_to_mtd(nand);
uint8_t *feature;
unsigned long rate;
int ret;
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c 
b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 802adb0..38b07c7 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -107,7 +107,7 @@ static irqreturn_t bch_irq(int irq, void *cookie)
 static inline int get_ecc_strength(struct gpmi_nand_data *this)
 {
struct bch_geometry *geo = >bch_geometry;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand);
int ecc_strength;
 
ecc_strength = ((mtd->oobsize - geo->metadata_size) * 8)
@@ -139,8 +139,8 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data 
*this)
 static bool set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 {
struct bch_geometry *geo = >bch_geometry;
-   struct mtd_info *mtd = >mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >nand;
+   struct mtd_info *mtd = nand_to_mtd(chip);
struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree;
unsigned int block_mark_bit_offset;
 
@@ -257,7 +257,7 @@ static bool set_geometry_by_ecc_info(struct gpmi_nand_data 
*this)
 static int legacy_set_geometry(struct gpmi_nand_data *this)
 {
struct bch_geometry *geo = >bch_geometry;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand);
unsigned int metadata_size;
unsigned int status_size;
unsigned int block_mark_bit_offset;
@@ -804,7 +804,7 @@ static int gpmi_alloc_dma_buffer(struct gpmi_nand_data 
*this)
 {
struct bch_geometry *geo = >bch_geometry;
struct device *dev = this->dev;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand);
 
/* [1] Allocate a command buffer. PAGE_SIZE is enough. */
this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
@@ -1600,8 +1600,8 @@ static int mx23_check_transcription_stamp(struct 
gpmi_nand_data *this)
 {
struct boot_rom_geometry *rom_geo = >rom_geometry;
struct device *dev = this->dev;
-   struct mtd_info *mtd = >mtd;
struct nand_chip *chip = >nand;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int search_area_size_in_strides;
unsigned int stride;
unsigned int page;
@@ -1655,8 +1655,8 @@ static int mx23_write_transcription_stamp(struct 
gpmi_nand_data *this)
 {
struct device *dev = this->dev;
struct boot_rom_geometry *rom_geo = >rom_geometry;
-   struct mtd_info *mtd = >mtd;
struct nand_chip *chip = >nand;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int block_size_in_pages;
unsigned int search_area_size_in_strides;
unsigned int search_area_size_in_pages;
@@ -1735,7 +1735,7 @@ static int mx23_boot_init(struct gpmi_nand_data  *this)
 {
struct device *dev = this->dev;
struct nand_chip *chip = >nand;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int block_count;
unsigned int block;
int chipnr;
@@ -1831,14 +1831,13 @@ static int gpmi_set_geometry(struct gpmi_nand_data 
*this)
 
 static void gpmi_nand_exit(struct gpmi_nand_data *this)
 {
-   nand_release(>mtd);
+  

[PATCH v4 21/58] mtd: nand: fsmc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsmc_nand.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 499fc59..4c68e7a 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -299,7 +299,6 @@ static struct fsmc_eccplace fsmc_ecc4_sp_place = {
  */
 struct fsmc_nand_data {
u32 pid;
-   struct mtd_info mtd;
struct nand_chipnand;
struct mtd_partition*partitions;
unsigned intnr_partitions;
@@ -328,7 +327,7 @@ struct fsmc_nand_data {
 
 static inline struct fsmc_nand_data *mtd_to_fsmc(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct fsmc_nand_data, mtd);
+   return container_of(mtd_to_nand(mtd), struct fsmc_nand_data, nand);
 }
 
 /* Assert CS signal based on chipnr */
@@ -1008,13 +1007,13 @@ static int __init fsmc_nand_probe(struct 
platform_device *pdev)
init_completion(>dma_access_complete);
 
/* Link all private pointers */
-   mtd = >mtd;
+   mtd = nand_to_mtd(>nand);
nand = >nand;
mtd->priv = nand;
nand->priv = host;
nand_set_flash_node(nand, np);
 
-   host->mtd.dev.parent = >dev;
+   mtd->dev.parent = >dev;
nand->IO_ADDR_R = host->data_va;
nand->IO_ADDR_W = host->data_va;
nand->cmd_ctrl = fsmc_cmd_ctrl;
@@ -1077,14 +1076,14 @@ static int __init fsmc_nand_probe(struct 
platform_device *pdev)
/*
 * Scan to find existence of the device
 */
-   if (nand_scan_ident(>mtd, 1, NULL)) {
+   if (nand_scan_ident(mtd, 1, NULL)) {
ret = -ENXIO;
dev_err(>dev, "No NAND Device found!\n");
goto err_scan_ident;
}
 
if (AMBA_REV_BITS(host->pid) >= 8) {
-   switch (host->mtd.oobsize) {
+   switch (mtd->oobsize) {
case 16:
nand->ecc.layout = _ecc4_16_layout;
host->ecc_place = _ecc4_sp_place;
@@ -1135,7 +1134,7 @@ static int __init fsmc_nand_probe(struct platform_device 
*pdev)
 * generated later in nand_bch_init() later.
 */
if (nand->ecc.mode != NAND_ECC_SOFT_BCH) {
-   switch (host->mtd.oobsize) {
+   switch (mtd->oobsize) {
case 16:
nand->ecc.layout = _ecc1_16_layout;
break;
@@ -1156,7 +1155,7 @@ static int __init fsmc_nand_probe(struct platform_device 
*pdev)
}
 
/* Second stage of scan to fill MTD data-structures */
-   if (nand_scan_tail(>mtd)) {
+   if (nand_scan_tail(mtd)) {
ret = -ENXIO;
goto err_probe;
}
@@ -1171,9 +1170,8 @@ static int __init fsmc_nand_probe(struct platform_device 
*pdev)
/*
 * Check for partition info passed
 */
-   host->mtd.name = "nand";
-   ret = mtd_device_register(>mtd, host->partitions,
- host->nr_partitions);
+   mtd->name = "nand";
+   ret = mtd_device_register(mtd, host->partitions, host->nr_partitions);
if (ret)
goto err_probe;
 
@@ -1203,7 +1201,7 @@ static int fsmc_nand_remove(struct platform_device *pdev)
struct fsmc_nand_data *host = platform_get_drvdata(pdev);
 
if (host) {
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>nand));
 
if (host->mode == USE_DMA_ACCESS) {
dma_release_channel(host->write_dma_chan);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 10/58] mtd: nand: brcm: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/brcmnand/brcmnand.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
b/drivers/mtd/nand/brcmnand/brcmnand.c
index 190a99a..26b64bc 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -178,7 +178,6 @@ struct brcmnand_host {
struct list_headnode;
 
struct nand_chipchip;
-   struct mtd_info mtd;
struct platform_device  *pdev;
int cs;
 
@@ -1074,7 +1073,7 @@ static int brcmnand_low_level_op(struct brcmnand_host 
*host,
 enum brcmnand_llop_type type, u32 data,
 bool last_op)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct nand_chip *chip = >chip;
struct brcmnand_controller *ctrl = host->ctrl;
u32 tmp;
@@ -1802,7 +1801,7 @@ static inline int get_blk_adr_bytes(u64 size, u32 
writesize)
 
 static int brcmnand_setup_dev(struct brcmnand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct nand_chip *chip = >chip;
struct brcmnand_controller *ctrl = host->ctrl;
struct brcmnand_cfg *cfg = >hwcfg;
@@ -1916,7 +1915,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host, 
struct device_node *dn)
return -ENXIO;
}
 
-   mtd = >mtd;
+   mtd = nand_to_mtd(>chip);
chip = >chip;
 
nand_set_flash_node(chip, dn);
@@ -2060,8 +2059,8 @@ static int brcmnand_resume(struct device *dev)
}
 
list_for_each_entry(host, >host_list, node) {
-   struct mtd_info *mtd = >mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
brcmnand_save_restore_cs_config(host, 1);
 
@@ -2262,7 +2261,7 @@ int brcmnand_remove(struct platform_device *pdev)
struct brcmnand_host *host;
 
list_for_each_entry(host, >host_list, node)
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
dev_set_drvdata(>dev, NULL);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 12/58] mtd: nand: cmx270: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/cmx270_nand.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 43bded6..6b26e0c 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -160,10 +160,8 @@ static int __init cmx270_init(void)
gpio_direction_input(GPIO_NAND_RB);
 
/* Allocate memory for MTD device structure and private data */
-   cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) +
- sizeof(struct nand_chip),
- GFP_KERNEL);
-   if (!cmx270_nand_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
ret = -ENOMEM;
goto err_kzalloc;
}
@@ -175,8 +173,7 @@ static int __init cmx270_init(void)
goto err_ioremap;
}
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *)(_nand_mtd[1]);
+   cmx270_nand_mtd = nand_to_mtd(this);
 
/* Link the private data with the MTD structure */
cmx270_nand_mtd->owner = THIS_MODULE;
@@ -216,7 +213,7 @@ static int __init cmx270_init(void)
 err_scan:
iounmap(cmx270_nand_io);
 err_ioremap:
-   kfree(cmx270_nand_mtd);
+   kfree(this);
 err_kzalloc:
gpio_free(GPIO_NAND_RB);
 err_gpio_request:
@@ -241,7 +238,7 @@ static void __exit cmx270_cleanup(void)
iounmap(cmx270_nand_io);
 
/* Free the MTD device structure */
-   kfree (cmx270_nand_mtd);
+   kfree(mtd_to_nand(cmx270_nand_mtd));
 }
 module_exit(cmx270_cleanup);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 14/58] mtd: nand: davinci: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/davinci_nand.c | 30 --
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index b5978d5..b1f69f9 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -53,7 +53,6 @@
  * outputs in a "wire-AND" configuration, with no per-chip signals.
  */
 struct davinci_nand_info {
-   struct mtd_info mtd;
struct nand_chipchip;
struct nand_ecclayout   ecclayout;
 
@@ -80,8 +79,10 @@ struct davinci_nand_info {
 static DEFINE_SPINLOCK(davinci_nand_lock);
 static bool ecc4_busy;
 
-#define to_davinci_nand(m) container_of(m, struct davinci_nand_info, mtd)
-
+static inline struct davinci_nand_info *to_davinci_nand(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct davinci_nand_info, chip);
+}
 
 static inline unsigned int davinci_nand_readl(struct davinci_nand_info *info,
int offset)
@@ -636,6 +637,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
int ret;
uint32_tval;
nand_ecc_modes_tecc_mode;
+   struct mtd_info *mtd;
 
pdata = nand_davinci_get_pdata(pdev);
if (IS_ERR(pdata))
@@ -682,8 +684,9 @@ static int nand_davinci_probe(struct platform_device *pdev)
info->base  = base;
info->vaddr = vaddr;
 
-   info->mtd.priv  = >chip;
-   info->mtd.dev.parent= >dev;
+   mtd = nand_to_mtd(>chip);
+   mtd->priv   = >chip;
+   mtd->dev.parent = >dev;
nand_set_flash_node(>chip, pdev->dev.of_node);
 
info->chip.IO_ADDR_R= vaddr;
@@ -785,7 +788,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
spin_unlock_irq(_nand_lock);
 
/* Scan to find existence of the device(s) */
-   ret = nand_scan_ident(>mtd, pdata->mask_chipsel ? 2 : 1, NULL);
+   ret = nand_scan_ident(mtd, pdata->mask_chipsel ? 2 : 1, NULL);
if (ret < 0) {
dev_dbg(>dev, "no NAND chip(s) found\n");
goto err;
@@ -797,9 +800,9 @@ static int nand_davinci_probe(struct platform_device *pdev)
 * usable:  10 bytes are needed, not 6.
 */
if (pdata->ecc_bits == 4) {
-   int chunks = info->mtd.writesize / 512;
+   int chunks = mtd->writesize / 512;
 
-   if (!chunks || info->mtd.oobsize < 16) {
+   if (!chunks || mtd->oobsize < 16) {
dev_dbg(>dev, "too small\n");
ret = -EINVAL;
goto err;
@@ -811,8 +814,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
 */
if (chunks == 1) {
info->ecclayout = hwecc4_small;
-   info->ecclayout.oobfree[1].length =
-   info->mtd.oobsize - 16;
+   info->ecclayout.oobfree[1].length = mtd->oobsize - 16;
goto syndrome_done;
}
if (chunks == 4) {
@@ -833,15 +835,15 @@ syndrome_done:
info->chip.ecc.layout = >ecclayout;
}
 
-   ret = nand_scan_tail(>mtd);
+   ret = nand_scan_tail(mtd);
if (ret < 0)
goto err;
 
if (pdata->parts)
-   ret = mtd_device_parse_register(>mtd, NULL, NULL,
+   ret = mtd_device_parse_register(mtd, NULL, NULL,
pdata->parts, pdata->nr_parts);
else
-   ret = mtd_device_register(>mtd, NULL, 0);
+   ret = mtd_device_register(mtd, NULL, 0);
if (ret < 0)
goto err;
 
@@ -871,7 +873,7 @@ static int nand_davinci_remove(struct platform_device *pdev)
ecc4_busy = false;

[PATCH v4 07/58] mtd: nand: au1550nd: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/au1550nd.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 73fceb8..280e5b6 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -23,7 +23,6 @@
 
 
 struct au1550nd_ctx {
-   struct mtd_info info;
struct nand_chip chip;
 
int cs;
@@ -197,8 +196,9 @@ static void au_read_buf16(struct mtd_info *mtd, u_char 
*buf, int len)
 
 static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
 {
-   struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
struct nand_chip *this = mtd_to_nand(mtd);
+   struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx,
+   chip);
 
switch (cmd) {
 
@@ -267,8 +267,9 @@ static void au1550_select_chip(struct mtd_info *mtd, int 
chip)
  */
 static void au1550_command(struct mtd_info *mtd, unsigned command, int column, 
int page_addr)
 {
-   struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
struct nand_chip *this = mtd_to_nand(mtd);
+   struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx,
+   chip);
int ce_override = 0, i;
unsigned long flags = 0;
 
@@ -405,6 +406,7 @@ static int au1550nd_probe(struct platform_device *pdev)
struct au1550nd_platdata *pd;
struct au1550nd_ctx *ctx;
struct nand_chip *this;
+   struct mtd_info *mtd;
struct resource *r;
int ret, cs;
 
@@ -438,8 +440,9 @@ static int au1550nd_probe(struct platform_device *pdev)
}
 
this = >chip;
-   ctx->info.priv = this;
-   ctx->info.dev.parent = >dev;
+   mtd = nand_to_mtd(this);
+   mtd->priv = this;
+   mtd->dev.parent = >dev;
 
/* figure out which CS# r->start belongs to */
cs = find_nand_cs(r->start);
@@ -467,13 +470,13 @@ static int au1550nd_probe(struct platform_device *pdev)
this->write_buf = (pd->devwidth) ? au_write_buf16 : au_write_buf;
this->read_buf = (pd->devwidth) ? au_read_buf16 : au_read_buf;
 
-   ret = nand_scan(>info, 1);
+   ret = nand_scan(mtd, 1);
if (ret) {
dev_err(>dev, "NAND scan failed with %d\n", ret);
goto out3;
}
 
-   mtd_device_register(>info, pd->parts, pd->num_parts);
+   mtd_device_register(mtd, pd->parts, pd->num_parts);
 
platform_set_drvdata(pdev, ctx);
 
@@ -493,7 +496,7 @@ static int au1550nd_remove(struct platform_device *pdev)
struct au1550nd_ctx *ctx = platform_get_drvdata(pdev);
struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-   nand_release(>info);
+   nand_release(nand_to_mtd(>chip));
iounmap(ctx->base);
release_mem_region(r->start, 0x1000);
kfree(ctx);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 02/58] mtd: nand: fsmc: create and use mtd_to_fsmc()

2015-12-10 Thread Boris Brezillon
Create and use mtd_to_fsmc() to avoid duplication of
container_of(mtd, struct fsmc_nand_data, mtd) calls.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/fsmc_nand.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 1c6c399..499fc59 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -326,13 +326,18 @@ struct fsmc_nand_data {
void(*select_chip)(uint32_t bank, uint32_t busw);
 };
 
+static inline struct fsmc_nand_data *mtd_to_fsmc(struct mtd_info *mtd)
+{
+   return container_of(mtd, struct fsmc_nand_data, mtd);
+}
+
 /* Assert CS signal based on chipnr */
 static void fsmc_select_chip(struct mtd_info *mtd, int chipnr)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
struct fsmc_nand_data *host;
 
-   host = container_of(mtd, struct fsmc_nand_data, mtd);
+   host = mtd_to_fsmc(mtd);
 
switch (chipnr) {
case -1:
@@ -359,8 +364,7 @@ static void fsmc_select_chip(struct mtd_info *mtd, int 
chipnr)
 static void fsmc_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
struct nand_chip *this = mtd_to_nand(mtd);
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
unsigned int bank = host->bank;
 
@@ -445,8 +449,7 @@ static void fsmc_nand_setup(void __iomem *regs, uint32_t 
bank,
  */
 static void fsmc_enable_hwecc(struct mtd_info *mtd, int mode)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
uint32_t bank = host->bank;
 
@@ -466,8 +469,7 @@ static void fsmc_enable_hwecc(struct mtd_info *mtd, int 
mode)
 static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const uint8_t *data,
uint8_t *ecc)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
uint32_t bank = host->bank;
uint32_t ecc_tmp;
@@ -517,8 +519,7 @@ static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const 
uint8_t *data,
 static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data,
uint8_t *ecc)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
uint32_t bank = host->bank;
uint32_t ecc_tmp;
@@ -674,9 +675,8 @@ static void fsmc_read_buf(struct mtd_info *mtd, uint8_t 
*buf, int len)
  */
 static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-   struct fsmc_nand_data *host;
+   struct fsmc_nand_data *host  = mtd_to_fsmc(mtd);
 
-   host = container_of(mtd, struct fsmc_nand_data, mtd);
dma_xfer(host, buf, len, DMA_FROM_DEVICE);
 }
 
@@ -689,9 +689,8 @@ static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t 
*buf, int len)
 static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
int len)
 {
-   struct fsmc_nand_data *host;
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
 
-   host = container_of(mtd, struct fsmc_nand_data, mtd);
dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE);
 }
 
@@ -712,8 +711,7 @@ static void fsmc_write_buf_dma(struct mtd_info *mtd, const 
uint8_t *buf,
 static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 uint8_t *buf, int oob_required, int page)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
struct fsmc_eccplace *ecc_place = host->ecc_place;
int i, j, s, stat, eccsize = chip->ecc.size;
int eccbytes = chip->ecc.bytes;
@@ -782,9 +780,8 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
 static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
 uint8_t *read_ecc, uint8_t *calc_ecc)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
struct nand_chip *chip = mtd_to_nand(mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
unsigned int bank = host->bank;
uint32_t err_idx[8];
-- 
2.1.4


[PATCH v4 57/58] mtd: nand: make use of nand_set/get_controller_data() helpers

2015-12-10 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/ams-delta.c |  6 +--
 drivers/mtd/nand/atmel_nand.c| 55 +++---
 drivers/mtd/nand/bcm47xxnflash/main.c|  2 +-
 drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c | 16 +++
 drivers/mtd/nand/bf5xx_nand.c|  2 +-
 drivers/mtd/nand/brcmnand/brcmnand.c | 30 ++--
 drivers/mtd/nand/cafe_nand.c | 24 +-
 drivers/mtd/nand/diskonchip.c| 70 ++--
 drivers/mtd/nand/docg4.c | 42 -
 drivers/mtd/nand/fsl_elbc_nand.c | 22 -
 drivers/mtd/nand/fsl_ifc_nand.c  | 26 +--
 drivers/mtd/nand/fsmc_nand.c |  2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c   | 28 +--
 drivers/mtd/nand/hisi504_nand.c  | 20 
 drivers/mtd/nand/lpc32xx_mlc.c   | 19 
 drivers/mtd/nand/lpc32xx_slc.c   | 20 
 drivers/mtd/nand/mpc5121_nfc.c   | 24 +-
 drivers/mtd/nand/mxc_nand.c  | 36 +++---
 drivers/mtd/nand/nandsim.c   |  4 +-
 drivers/mtd/nand/ndfc.c  | 16 +++
 drivers/mtd/nand/orion_nand.c|  4 +-
 drivers/mtd/nand/plat_nand.c |  2 +-
 drivers/mtd/nand/pxa3xx_nand.c   | 22 -
 drivers/mtd/nand/r852.c  |  6 +--
 drivers/mtd/nand/s3c2410.c   |  4 +-
 drivers/mtd/nand/socrates_nand.c | 11 +++--
 drivers/mtd/nand/txx9ndfmc.c |  8 ++--
 27 files changed, 262 insertions(+), 259 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 1a18938..68b58c8 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -65,7 +65,7 @@ static struct mtd_partition partition_info[] = {
 static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte)
 {
struct nand_chip *this = mtd_to_nand(mtd);
-   void __iomem *io_base = this->priv;
+   void __iomem *io_base = (void __iomem *)nand_get_controller_data(this);
 
writew(0, io_base + OMAP_MPUIO_IO_CNTL);
writew(byte, this->IO_ADDR_W);
@@ -78,7 +78,7 @@ static u_char ams_delta_read_byte(struct mtd_info *mtd)
 {
u_char res;
struct nand_chip *this = mtd_to_nand(mtd);
-   void __iomem *io_base = this->priv;
+   void __iomem *io_base = (void __iomem *)nand_get_controller_data(this);
 
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE, 0);
ndelay(40);
@@ -206,7 +206,7 @@ static int ams_delta_init(struct platform_device *pdev)
goto out_free;
}
 
-   this->priv = io_base;
+   nand_set_controller_data(this, (void *)io_base);
 
/* Set address of NAND IO lines */
this->IO_ADDR_R = io_base + OMAP_MPUIO_INPUT_LATCH;
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 18c4e14..2ff0f0e 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -182,7 +182,7 @@ static void atmel_nand_disable(struct atmel_nand_host *host)
 static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int 
ctrl)
 {
struct nand_chip *nand_chip = mtd_to_nand(mtd);
-   struct atmel_nand_host *host = nand_chip->priv;
+   struct atmel_nand_host *host = nand_get_controller_data(nand_chip);
 
if (ctrl & NAND_CTRL_CHANGE) {
if (ctrl & NAND_NCE)
@@ -205,7 +205,7 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int 
cmd, unsigned int ctrl
 static int atmel_nand_device_ready(struct mtd_info *mtd)
 {
struct nand_chip *nand_chip = mtd_to_nand(mtd);
-   struct atmel_nand_host *host = nand_chip->priv;
+   struct atmel_nand_host *host = nand_get_controller_data(nand_chip);
 
return gpio_get_value(host->board.rdy_pin) ^
 !!host->board.rdy_pin_active_low;
@@ -215,7 +215,7 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 static int atmel_nand_set_enable_ready_pins(struct mtd_info *mtd)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct atmel_nand_host *host = chip->priv;
+   struct atmel_nand_host *host = nand_get_controller_data(chip);
int res = 0;
 
if (gpio_is_valid(host->board.rdy_pin)) {
@@ -267,7 +267,7 @@ static int atmel_nand_set_enable_ready_pins(struct mtd_info 
*mtd)
 static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len)
 {
struct nand_chip*nand_chip = mtd_to_nand(mtd);
-   struct atmel_nand_host *host = nand_chip->priv;
+   struct atmel_nand_host *host = nand_get_controller_data(nand_chip);
 
if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) {
   

[PATCH v4 24/58] mtd: nand: hisi504: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/hisi504_nand.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/hisi504_nand.c b/drivers/mtd/nand/hisi504_nand.c
index 6358d4a..6e6e482 100644
--- a/drivers/mtd/nand/hisi504_nand.c
+++ b/drivers/mtd/nand/hisi504_nand.c
@@ -134,7 +134,6 @@
 
 struct hinfc_host {
struct nand_chipchip;
-   struct mtd_info mtd;
struct device   *dev;
void __iomem*iobase;
void __iomem*mmio;
@@ -189,8 +188,8 @@ static void wait_controller_finished(struct hinfc_host 
*host)
 
 static void hisi_nfc_dma_transfer(struct hinfc_host *host, int todev)
 {
-   struct mtd_info *mtd = >mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned long val;
int ret;
 
@@ -262,7 +261,7 @@ static int hisi_nfc_send_cmd_pageprog(struct hinfc_host 
*host)
 
 static int hisi_nfc_send_cmd_readstart(struct hinfc_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
if ((host->addr_value[0] == host->cache_addr_value[0]) &&
(host->addr_value[1] == host->cache_addr_value[1]))
@@ -643,7 +642,7 @@ static int hisi_nfc_ecc_probe(struct hinfc_host *host)
int size, strength, ecc_bits;
struct device *dev = host->dev;
struct nand_chip *chip = >chip;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(chip);
struct device_node *np = host->dev->of_node;
 
size = of_get_nand_ecc_step_size(np);
@@ -712,7 +711,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, host);
chip = >chip;
-   mtd  = >mtd;
+   mtd  = nand_to_mtd(chip);
 
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
@@ -822,7 +821,7 @@ err_res:
 static int hisi_nfc_remove(struct platform_device *pdev)
 {
struct hinfc_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
nand_release(mtd);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 22/58] mtd: nand: gpio: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/gpio.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index d57a07a..99dd74c 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -35,12 +35,14 @@
 
 struct gpiomtd {
void __iomem*io_sync;
-   struct mtd_info mtd_info;
struct nand_chipnand_chip;
struct gpio_nand_platdata plat;
 };
 
-#define gpio_nand_getpriv(x) container_of(x, struct gpiomtd, mtd_info)
+static inline struct gpiomtd *gpio_nand_getpriv(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct gpiomtd, nand_chip);
+}
 
 
 #ifdef CONFIG_ARM
@@ -195,7 +197,7 @@ static int gpio_nand_remove(struct platform_device *pdev)
 {
struct gpiomtd *gpiomtd = platform_get_drvdata(pdev);
 
-   nand_release(>mtd_info);
+   nand_release(nand_to_mtd(>nand_chip));
 
if (gpio_is_valid(gpiomtd->plat.gpio_nwp))
gpio_set_value(gpiomtd->plat.gpio_nwp, 0);
@@ -208,6 +210,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
 {
struct gpiomtd *gpiomtd;
struct nand_chip *chip;
+   struct mtd_info *mtd;
struct resource *res;
int ret = 0;
 
@@ -274,24 +277,24 @@ static int gpio_nand_probe(struct platform_device *pdev)
chip->chip_delay= gpiomtd->plat.chip_delay;
chip->cmd_ctrl  = gpio_nand_cmd_ctrl;
 
-   gpiomtd->mtd_info.priv  = chip;
-   gpiomtd->mtd_info.dev.parent = >dev;
+   mtd = nand_to_mtd(chip);
+   mtd->priv   = chip;
+   mtd->dev.parent = >dev;
 
platform_set_drvdata(pdev, gpiomtd);
 
if (gpio_is_valid(gpiomtd->plat.gpio_nwp))
gpio_direction_output(gpiomtd->plat.gpio_nwp, 1);
 
-   if (nand_scan(>mtd_info, 1)) {
+   if (nand_scan(mtd, 1)) {
ret = -ENXIO;
goto err_wp;
}
 
if (gpiomtd->plat.adjust_parts)
-   gpiomtd->plat.adjust_parts(>plat,
-  gpiomtd->mtd_info.size);
+   gpiomtd->plat.adjust_parts(>plat, mtd->size);
 
-   ret = mtd_device_register(>mtd_info, gpiomtd->plat.parts,
+   ret = mtd_device_register(mtd, gpiomtd->plat.parts,
  gpiomtd->plat.num_parts);
if (!ret)
return 0;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 26/58] mtd: nand: lpc32xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/lpc32xx_mlc.c | 7 +++
 drivers/mtd/nand/lpc32xx_slc.c | 7 +++
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 3738856..3400b3f 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -173,7 +173,6 @@ struct lpc32xx_nand_host {
struct nand_chipnand_chip;
struct lpc32xx_mlc_platform_data *pdata;
struct clk  *clk;
-   struct mtd_info mtd;
void __iomem*io_base;
int irq;
struct lpc32xx_nand_cfg_mlc *ncfg;
@@ -566,7 +565,7 @@ static void lpc32xx_ecc_enable(struct mtd_info *mtd, int 
mode)
 
 static int lpc32xx_dma_setup(struct lpc32xx_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
dma_cap_mask_t mask;
 
if (!host->pdata || !host->pdata->dma_filter) {
@@ -660,8 +659,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)

host->io_base_phy = rc->start;
 
-   mtd = >mtd;
nand_chip = >nand_chip;
+   mtd = nand_to_mtd(nand_chip);
if (pdev->dev.of_node)
host->ncfg = lpc32xx_parse_dt(>dev);
if (!host->ncfg) {
@@ -814,7 +813,7 @@ err_exit1:
 static int lpc32xx_nand_remove(struct platform_device *pdev)
 {
struct lpc32xx_nand_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
free_irq(host->irq, host);
diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
index fcd9fac..61b2961 100644
--- a/drivers/mtd/nand/lpc32xx_slc.c
+++ b/drivers/mtd/nand/lpc32xx_slc.c
@@ -204,7 +204,6 @@ struct lpc32xx_nand_host {
struct nand_chipnand_chip;
struct lpc32xx_slc_platform_data *pdata;
struct clk  *clk;
-   struct mtd_info mtd;
void __iomem*io_base;
struct lpc32xx_nand_cfg_slc *ncfg;
 
@@ -703,7 +702,7 @@ static int lpc32xx_nand_write_page_raw_syndrome(struct 
mtd_info *mtd,
 
 static int lpc32xx_nand_dma_setup(struct lpc32xx_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
dma_cap_mask_t mask;
 
if (!host->pdata || !host->pdata->dma_filter) {
@@ -799,8 +798,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 
host->pdata = dev_get_platdata(>dev);
 
-   mtd = >mtd;
chip = >nand_chip;
+   mtd = nand_to_mtd(chip);
chip->priv = host;
nand_set_flash_node(chip, pdev->dev.of_node);
mtd->priv = chip;
@@ -932,7 +931,7 @@ static int lpc32xx_nand_remove(struct platform_device *pdev)
 {
uint32_t tmp;
struct lpc32xx_nand_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
dma_release_channel(host->dma_chan);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 55/58] mtd: nand: add helpers to access ->priv

2015-12-10 Thread Boris Brezillon
Add two helpers to access the field reserved for private controller data.
This makes it clearer what this field is reserved for and ease future
refactoring.

Signed-off-by: Boris Brezillon 
---
 include/linux/mtd/nand.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 2bee2e4..4aed4b2 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -739,6 +739,16 @@ static inline struct mtd_info *nand_to_mtd(struct 
nand_chip *chip)
return >mtd;
 }
 
+static inline void *nand_get_controller_data(struct nand_chip *chip)
+{
+   return chip->priv;
+}
+
+static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
+{
+   chip->priv = priv;
+}
+
 /*
  * NAND Flash Manufacturer ID Codes
  */
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 53/58] mtd: nand: simplify nand_dt_init() usage

2015-12-10 Thread Boris Brezillon
nand_dt_init() function requires 3 arguments where it actually needs one
(dn and mtd can both be retrieved from chip). Drop these parameters.

Testing for dn != NULL inside nand_dt_init() also helps simplifying the
caller code.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/nand_base.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5aec154..ae3fd2a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3937,11 +3937,17 @@ ident_done:
return type;
 }
 
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip,
-   struct device_node *dn)
+static int nand_dt_init(struct nand_chip *chip)
 {
+   struct device_node *dn = nand_get_flash_node(chip);
int ecc_mode, ecc_strength, ecc_step;
 
+   if (!dn)
+   return 0;
+
+   /* MTD can automatically handle DT partitions, etc. */
+   mtd_set_of_node(nand_to_mtd(chip), dn);
+
if (of_get_nand_bus_width(dn) == 16)
chip->options |= NAND_BUSWIDTH_16;
 
@@ -3989,14 +3995,9 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
struct nand_flash_dev *type;
int ret;
 
-   if (nand_get_flash_node(chip)) {
-   /* MTD can automatically handle DT partitions, etc. */
-   mtd_set_of_node(mtd, nand_get_flash_node(chip));
-
-   ret = nand_dt_init(mtd, chip, nand_get_flash_node(chip));
-   if (ret)
-   return ret;
-   }
+   ret = nand_dt_init(chip);
+   if (ret)
+   return ret;
 
/* Set the default functions */
nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 51/58] cris: nand: remove useless mtd->priv = chip assignments

2015-12-10 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon 
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 3 ---
 arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
index ee74e45..5aa3f51 100644
--- a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
@@ -149,9 +149,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
this = >chip;
crisv32_mtd = nand_to_mtd(this);
 
-   /* Link the private data with the MTD structure */
-   crisv32_mtd->priv = this;
-
/* Set address of NAND IO lines */
this->IO_ADDR_R = read_cs;
this->IO_ADDR_W = write_cs;
diff --git a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
index 5626297..a7c17b0 100644
--- a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
@@ -140,9 +140,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
bif_cfg.gated_csp1 = regk_bif_core_wr;
REG_WR(bif_core, regi_bif_core, rw_grp3_cfg, bif_cfg);
 
-   /* Link the private data with the MTD structure */
-   crisv32_mtd->priv = this;
-
/* Set address of NAND IO lines */
this->IO_ADDR_R = read_cs;
this->IO_ADDR_W = write_cs;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 58/58] staging: mt29f_spinand: make use of nand_set/get_controller_data() helpers

2015-12-10 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon 
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index b7d429d..197d112 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -32,7 +32,7 @@
 static inline struct spinand_state *mtd_to_state(struct mtd_info *mtd)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
struct spinand_state *state = (struct spinand_state *)info->priv;
 
return state;
@@ -633,7 +633,7 @@ static int spinand_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
u8 *p = buf;
int eccsize = chip->ecc.size;
int eccsteps = chip->ecc.steps;
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
 
enable_read_hw_ecc = 1;
 
@@ -679,7 +679,7 @@ static u8 spinand_read_byte(struct mtd_info *mtd)
 
 static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
 
unsigned long timeo = jiffies;
int retval, state = chip->state;
@@ -745,7 +745,7 @@ static void spinand_cmdfunc(struct mtd_info *mtd, unsigned 
int command,
int column, int page)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
struct spinand_state *state = (struct spinand_state *)info->priv;
 
switch (command) {
@@ -894,7 +894,7 @@ static int spinand_probe(struct spi_device *spi_nand)
 #endif
 
nand_set_flash_node(chip, spi_nand->dev.of_node);
-   chip->priv  = info;
+   nand_set_controller_data(chip, info);
chip->read_buf  = spinand_read_buf;
chip->write_buf = spinand_write_buf;
chip->read_byte = spinand_read_byte;
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 56/58] ARM: make use of nand_set/get_controller_data() helpers

2015-12-10 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon 
---
 arch/arm/mach-ixp4xx/ixdp425-setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c 
b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 333b0f9..508c2d7 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -77,7 +77,7 @@ static void
 ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
struct nand_chip *this = mtd_to_nand(mtd);
-   int offset = (int)this->priv;
+   int offset = (int)nand_get_controller_data(this);
 
if (ctrl & NAND_CTRL_CHANGE) {
if (ctrl & NAND_NCE) {
@@ -88,7 +88,7 @@ ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 
unsigned int ctrl)
 
offset = (ctrl & NAND_CLE) ? IXDP425_NAND_CMD_BYTE : 0;
offset |= (ctrl & NAND_ALE) ? IXDP425_NAND_ADDR_BYTE : 0;
-   this->priv = (void *)offset;
+   nand_set_controller_data(this, (void *)offset);
}
 
if (cmd != NAND_CMD_NONE)
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 52/58] staging: mt29f_spinand: remove useless mtd->priv = chip assignment

2015-12-10 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon 
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 8171b74..b7d429d 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -907,7 +907,6 @@ static int spinand_probe(struct spi_device *spi_nand)
 
dev_set_drvdata(_nand->dev, mtd);
 
-   mtd->priv = chip;
mtd->dev.parent = _nand->dev;
mtd->oobsize = 64;
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 39/58] mtd: nand: sh_flctl: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/sh_flctl.c  | 8 
 include/linux/mtd/sh_flctl.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index 57dc525..0ec4b04 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -607,13 +607,13 @@ static void execmd_read_page_sector(struct mtd_info *mtd, 
int page_addr)
case FL_REPAIRABLE:
dev_info(>pdev->dev,
"applied ecc on page 0x%x", page_addr);
-   flctl->mtd.ecc_stats.corrected++;
+   mtd->ecc_stats.corrected++;
break;
case FL_ERROR:
dev_warn(>pdev->dev,
"page 0x%x contains corrupted data\n",
page_addr);
-   flctl->mtd.ecc_stats.failed++;
+   mtd->ecc_stats.failed++;
break;
default:
;
@@ -1120,8 +1120,8 @@ static int flctl_probe(struct platform_device *pdev)
}
 
platform_set_drvdata(pdev, flctl);
-   flctl_mtd = >mtd;
nand = >chip;
+   flctl_mtd = nand_to_mtd(nand);
nand_set_flash_node(nand, pdev->dev.of_node);
flctl_mtd->priv = nand;
flctl_mtd->dev.parent = >dev;
@@ -1178,7 +1178,7 @@ static int flctl_remove(struct platform_device *pdev)
struct sh_flctl *flctl = platform_get_drvdata(pdev);
 
flctl_release_dma(flctl);
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
pm_runtime_disable(>dev);
 
return 0;
diff --git a/include/linux/mtd/sh_flctl.h b/include/linux/mtd/sh_flctl.h
index 1c28f88..76e3e88 100644
--- a/include/linux/mtd/sh_flctl.h
+++ b/include/linux/mtd/sh_flctl.h
@@ -143,7 +143,6 @@ enum flctl_ecc_res_t {
 struct dma_chan;
 
 struct sh_flctl {
-   struct mtd_info mtd;
struct nand_chipchip;
struct platform_device  *pdev;
struct dev_pm_qos_request pm_qos;
@@ -186,7 +185,7 @@ struct sh_flctl_platform_data {
 
 static inline struct sh_flctl *mtd_to_flctl(struct mtd_info *mtdinfo)
 {
-   return container_of(mtdinfo, struct sh_flctl, mtd);
+   return container_of(mtd_to_nand(mtdinfo), struct sh_flctl, chip);
 }
 
 #endif /* __SH_FLCTL_H__ */
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 43/58] mtd: nand: tmio: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/tmio_nand.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index 6d0cbe9..e7b82e1 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -103,7 +103,6 @@
 /*--*/
 
 struct tmio_nand {
-   struct mtd_info mtd;
struct nand_chip chip;
 
struct platform_device *dev;
@@ -119,7 +118,10 @@ struct tmio_nand {
unsigned read_good:1;
 };
 
-#define mtd_to_tmio(m) container_of(m, struct tmio_nand, mtd)
+static inline struct tmio_nand *mtd_to_tmio(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct tmio_nand, chip);
+}
 
 
 /*--*/
@@ -378,8 +380,8 @@ static int tmio_probe(struct platform_device *dev)
tmio->dev = dev;
 
platform_set_drvdata(dev, tmio);
-   mtd = >mtd;
nand_chip = >chip;
+   mtd = nand_to_mtd(nand_chip);
mtd->priv = nand_chip;
mtd->name = "tmio-nand";
mtd->dev.parent = >dev;
@@ -456,7 +458,7 @@ static int tmio_remove(struct platform_device *dev)
 {
struct tmio_nand *tmio = platform_get_drvdata(dev);
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
tmio_hw_stop(dev, tmio);
return 0;
 }
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 41/58] mtd: nand: socrates: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/socrates_nand.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index 2dfb1e0..c0ca0fd 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -30,7 +30,6 @@
 
 struct socrates_nand_host {
struct nand_chipnand_chip;
-   struct mtd_info mtd;
void __iomem*io_base;
struct device   *dev;
 };
@@ -159,8 +158,8 @@ static int socrates_nand_probe(struct platform_device 
*ofdev)
return -EIO;
}
 
-   mtd = >mtd;
nand_chip = >nand_chip;
+   mtd = nand_to_mtd(nand_chip);
host->dev = >dev;
 
nand_chip->priv = host; /* link the private data structures */
@@ -216,7 +215,7 @@ out:
 static int socrates_nand_remove(struct platform_device *ofdev)
 {
struct socrates_nand_host *host = dev_get_drvdata(>dev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
nand_release(mtd);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 42/58] mtd: nand: sunxi: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/sunxi_nand.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index 4ecd486..c29d659 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -234,7 +234,6 @@ struct sunxi_nand_hw_ecc {
 struct sunxi_nand_chip {
struct list_head node;
struct nand_chip nand;
-   struct mtd_info mtd;
unsigned long clk_rate;
u32 timing_cfg;
u32 timing_ctl;
@@ -991,6 +990,7 @@ static int sunxi_nand_chip_set_timings(struct 
sunxi_nand_chip *chip,
 static int sunxi_nand_chip_init_timings(struct sunxi_nand_chip *chip,
struct device_node *np)
 {
+   struct mtd_info *mtd = nand_to_mtd(>nand);
const struct nand_sdr_timings *timings;
int ret;
int mode;
@@ -1008,12 +1008,11 @@ static int sunxi_nand_chip_init_timings(struct 
sunxi_nand_chip *chip,
 
feature[0] = mode;
for (i = 0; i < chip->nsels; i++) {
-   chip->nand.select_chip(>mtd, i);
-   ret = chip->nand.onfi_set_features(>mtd,
-   >nand,
+   chip->nand.select_chip(mtd, i);
+   ret = chip->nand.onfi_set_features(mtd, >nand,
ONFI_FEATURE_ADDR_TIMING_MODE,
feature);
-   chip->nand.select_chip(>mtd, -1);
+   chip->nand.select_chip(mtd, -1);
if (ret)
return ret;
}
@@ -1336,7 +1335,7 @@ static int sunxi_nand_chip_init(struct device *dev, 
struct sunxi_nfc *nfc,
nand->write_buf = sunxi_nfc_write_buf;
nand->read_byte = sunxi_nfc_read_byte;
 
-   mtd = >mtd;
+   mtd = nand_to_mtd(nand);
mtd->dev.parent = dev;
mtd->priv = nand;
 
@@ -1407,7 +1406,7 @@ static void sunxi_nand_chips_cleanup(struct sunxi_nfc 
*nfc)
while (!list_empty(>chips)) {
chip = list_first_entry(>chips, struct sunxi_nand_chip,
node);
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>nand));
sunxi_nand_ecc_cleanup(>nand.ecc);
list_del(>node);
}
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 35/58] mtd: nand: plat: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/plat_nand.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 06ac6c6..796eb7d 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -20,7 +20,6 @@
 
 struct plat_nand_data {
struct nand_chipchip;
-   struct mtd_info mtd;
void __iomem*io_base;
 };
 
@@ -31,6 +30,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 {
struct platform_nand_data *pdata = dev_get_platdata(>dev);
struct plat_nand_data *data;
+   struct mtd_info *mtd;
struct resource *res;
const char **part_types;
int err = 0;
@@ -58,8 +58,9 @@ static int plat_nand_probe(struct platform_device *pdev)
 
data->chip.priv = 
nand_set_flash_node(>chip, pdev->dev.of_node);
-   data->mtd.priv = >chip;
-   data->mtd.dev.parent = >dev;
+   mtd = nand_to_mtd(>chip);
+   mtd->priv = >chip;
+   mtd->dev.parent = >dev;
 
data->chip.IO_ADDR_R = data->io_base;
data->chip.IO_ADDR_W = data->io_base;
@@ -87,21 +88,21 @@ static int plat_nand_probe(struct platform_device *pdev)
}
 
/* Scan to find existence of the device */
-   if (nand_scan(>mtd, pdata->chip.nr_chips)) {
+   if (nand_scan(mtd, pdata->chip.nr_chips)) {
err = -ENXIO;
goto out;
}
 
part_types = pdata->chip.part_probe_types;
 
-   err = mtd_device_parse_register(>mtd, part_types, NULL,
+   err = mtd_device_parse_register(mtd, part_types, NULL,
pdata->chip.partitions,
pdata->chip.nr_partitions);
 
if (!err)
return err;
 
-   nand_release(>mtd);
+   nand_release(mtd);
 out:
if (pdata->ctrl.remove)
pdata->ctrl.remove(pdev);
@@ -116,7 +117,7 @@ static int plat_nand_remove(struct platform_device *pdev)
struct plat_nand_data *data = platform_get_drvdata(pdev);
struct platform_nand_data *pdata = dev_get_platdata(>dev);
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
if (pdata->ctrl.remove)
pdata->ctrl.remove(pdev);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 38/58] mtd: nand: s3c2410: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/s3c2410.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index e658b29..c074a49 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -104,7 +104,6 @@ struct s3c2410_nand_info;
  * @scan_res: The result from calling nand_scan_ident().
 */
 struct s3c2410_nand_mtd {
-   struct mtd_info mtd;
struct nand_chipchip;
struct s3c2410_nand_set *set;
struct s3c2410_nand_info*info;
@@ -168,7 +167,8 @@ struct s3c2410_nand_info {
 
 static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct s3c2410_nand_mtd, mtd);
+   return container_of(mtd_to_nand(mtd), struct s3c2410_nand_mtd,
+   chip);
 }
 
 static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
@@ -745,7 +745,7 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
 
for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
}
}
 
@@ -762,9 +762,11 @@ static int s3c2410_nand_add_partition(struct 
s3c2410_nand_info *info,
  struct s3c2410_nand_set *set)
 {
if (set) {
-   mtd->mtd.name = set->name;
+   struct mtd_info *mtdinfo = nand_to_mtd(>chip);
 
-   return mtd_device_parse_register(>mtd, NULL, NULL,
+   mtdinfo->name = set->name;
+
+   return mtd_device_parse_register(mtdinfo, NULL, NULL,
 set->partitions, set->nr_partitions);
}
 
@@ -786,6 +788,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info 
*info,
   struct s3c2410_nand_set *set)
 {
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
void __iomem *regs = info->regs;
 
chip->write_buf= s3c2410_nand_write_buf;
@@ -831,7 +834,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info 
*info,
chip->IO_ADDR_R = chip->IO_ADDR_W;
 
nmtd->info = info;
-   nmtd->mtd.priv = chip;
+   mtd->priv  = chip;
nmtd->set  = set;
 
 #ifdef CONFIG_MTD_NAND_S3C2410_HWECC
@@ -1012,19 +1015,21 @@ static int s3c24xx_nand_probe(struct platform_device 
*pdev)
nmtd = info->mtds;
 
for (setno = 0; setno < nr_sets; setno++, nmtd++) {
+   struct mtd_info *mtd = nand_to_mtd(>chip);
+
pr_debug("initialising set %d (%p, info %p)\n",
 setno, nmtd, info);
 
-   nmtd->mtd.dev.parent = >dev;
+   mtd->dev.parent = >dev;
s3c2410_nand_init_chip(info, nmtd, sets);
 
-   nmtd->scan_res = nand_scan_ident(>mtd,
+   nmtd->scan_res = nand_scan_ident(mtd,
 (sets) ? sets->nr_chips : 1,
 NULL);
 
if (nmtd->scan_res == 0) {
s3c2410_nand_update_chip(info, nmtd);
-   nand_scan_tail(>mtd);
+   nand_scan_tail(mtd);
s3c2410_nand_add_partition(info, nmtd, sets);
}
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 40/58] mtd: nand: sharpsl: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/sharpsl.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 84129e5..4b649fb 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -29,13 +29,15 @@
 #include 
 
 struct sharpsl_nand {
-   struct mtd_info mtd;
struct nand_chipchip;
 
void __iomem*io;
 };
 
-#define mtd_to_sharpsl(_mtd)   container_of(_mtd, struct sharpsl_nand, mtd)
+static inline struct sharpsl_nand *mtd_to_sharpsl(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct sharpsl_nand, chip);
+}
 
 /* register offset */
 #define ECCLPLB0x00/* line parity 7 - 0 bit */
@@ -109,6 +111,7 @@ static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, 
const u_char * dat,
 static int sharpsl_nand_probe(struct platform_device *pdev)
 {
struct nand_chip *this;
+   struct mtd_info *mtd;
struct resource *r;
int err = 0;
struct sharpsl_nand *sharpsl;
@@ -143,8 +146,9 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
this = (struct nand_chip *)(>chip);
 
/* Link the private data with the MTD structure */
-   sharpsl->mtd.priv = this;
-   sharpsl->mtd.dev.parent = >dev;
+   mtd = nand_to_mtd(this);
+   mtd->priv = this;
+   mtd->dev.parent = >dev;
 
platform_set_drvdata(pdev, sharpsl);
 
@@ -173,14 +177,14 @@ static int sharpsl_nand_probe(struct platform_device 
*pdev)
this->ecc.correct = nand_correct_data;
 
/* Scan to find existence of the device */
-   err = nand_scan(>mtd, 1);
+   err = nand_scan(mtd, 1);
if (err)
goto err_scan;
 
/* Register the partitions */
-   sharpsl->mtd.name = "sharpsl-nand";
+   mtd->name = "sharpsl-nand";
 
-   err = mtd_device_parse_register(>mtd, NULL, NULL,
+   err = mtd_device_parse_register(mtd, NULL, NULL,
data->partitions, data->nr_partitions);
if (err)
goto err_add;
@@ -189,7 +193,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
return 0;
 
 err_add:
-   nand_release(>mtd);
+   nand_release(mtd);
 
 err_scan:
iounmap(sharpsl->io);
@@ -207,7 +211,7 @@ static int sharpsl_nand_remove(struct platform_device *pdev)
struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev);
 
/* Release resources, unregister device */
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
iounmap(sharpsl->io);
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 36/58] mtd: nand: pxa3xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon 
---
 drivers/mtd/nand/pxa3xx_nand.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index dc39a98..c4d5788 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -167,7 +167,6 @@ enum pxa3xx_nand_variant {
 
 struct pxa3xx_nand_host {
struct nand_chipchip;
-   struct mtd_info *mtd;
void*info_data;
 
/* page size of attached chip */
@@ -450,14 +449,15 @@ static int pxa3xx_nand_init_timings_compat(struct 
pxa3xx_nand_host *host,
struct nand_chip *chip = >chip;
struct pxa3xx_nand_info *info = host->info_data;
const struct pxa3xx_nand_flash *f = NULL;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int i, id, ntypes;
 
ntypes = ARRAY_SIZE(builtin_flash_types);
 
-   chip->cmdfunc(host->mtd, NAND_CMD_READID, 0x00, -1);
+   chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
 
-   id = chip->read_byte(host->mtd);
-   id |= chip->read_byte(host->mtd) << 0x8;
+   id = chip->read_byte(mtd);
+   id |= chip->read_byte(mtd) << 0x8;
 
for (i = 0; i < ntypes; i++) {
f = _flash_types[i];
@@ -890,7 +890,7 @@ static void set_command_address(struct pxa3xx_nand_info 
*info,
 static void prepare_start_command(struct pxa3xx_nand_info *info, int command)
 {
struct pxa3xx_nand_host *host = info->host[info->cs];
-   struct mtd_info *mtd = host->mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
/* reset data and oob column point to handle data */
info->buf_start = 0;
@@ -943,7 +943,7 @@ static int prepare_set_command(struct pxa3xx_nand_info 
*info, int command,
struct mtd_info *mtd;
 
host = info->host[info->cs];
-   mtd = host->mtd;
+   mtd = nand_to_mtd(>chip);
addr_cycle = 0;
exec_cmd = 1;
 
@@ -1415,8 +1415,8 @@ static int pxa3xx_nand_config_ident(struct 
pxa3xx_nand_info *info)
 static void pxa3xx_nand_config_tail(struct pxa3xx_nand_info *info)
 {
struct pxa3xx_nand_host *host = info->host[info->cs];
-   struct mtd_info *mtd = host->mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0;
info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0;
@@ -1693,19 +1693,20 @@ static int alloc_nand_resource(struct platform_device 
*pdev)
pdata = dev_get_platdata(>dev);
if (pdata->num_cs <= 0)
return -ENODEV;
-   info = devm_kzalloc(>dev, sizeof(*info) + (sizeof(*mtd) +
-   sizeof(*host)) * pdata->num_cs, GFP_KERNEL);
+   info = devm_kzalloc(>dev,
+   sizeof(*info) + sizeof(*host) * pdata->num_cs,
+   GFP_KERNEL);
if (!info)
return -ENOMEM;
 
info->pdev = pdev;
info->variant = pxa3xx_nand_get_variant(pdev);
for (cs = 0; cs < pdata->num_cs; cs++) {
-   mtd = (void *)[1] + (sizeof(*mtd) + sizeof(*host)) * cs;
-   chip = (struct nand_chip *)([1]);
-   host = (struct pxa3xx_nand_host *)chip;
+   host = (void *)[1] + sizeof(*host) * cs;
+   chip = >chip;
+   chip->priv = host;
+   mtd = nand_to_mtd(chip);
info->host[cs] = host;
-   host->mtd = mtd;
host->cs = cs;
host->info_data = info;
mtd->priv = chip;
@@ -1833,7 +1834,7 @@ static int pxa3xx_nand_remove(struct platform_device 
*pdev)
clk_disable_unprepare(info->clk);
 
for (cs = 0; cs < pdata->num_cs; cs++)
-   nand_release(info->host[cs]->mtd);
+   nand_release(nand_to_mtd(>host[cs]->chip));
return 0;
 }
 
@@ -1904,7 +1905,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
info = platform_get_drvdata(pdev);
probe_success = 0;
for (cs = 0; cs < pdata->num_cs; cs++) {
-   struct mtd_info *mtd = info->host[cs]->mtd;
+   struct mtd_info *mtd = nand_to_mtd(>host[cs]->chip);
 
/*
 * The mtd name matches the one used in 'mtdparts' kernel
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: gdm72xx: add userspace data struct

2015-12-10 Thread Wim de With
This fixes the sparse warnings about dereferencing a userspace pointer.

However, gdm_wimax_ioctl_get_data and gdm_wimax_ioctl_set_data both
carefully check whether the pointers and data are valid, gdm_update_fsm
does not. It simply casts userspace data to struct fsm_s. I haven't
fixed this, and am not sure what to do about it.

Signed-off-by: Wim de With 
---
 drivers/staging/gdm72xx/gdm_wimax.c | 17 +
 drivers/staging/gdm72xx/wm_ioctl.h  |  7 ++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c 
b/drivers/staging/gdm72xx/gdm_wimax.c
index d9ddced..16eac61 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -368,7 +368,7 @@ static void kdelete(void **buf)
}
 }
 
-static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src)
+static int gdm_wimax_ioctl_get_data(struct udata_s *dst, struct data_s *src)
 {
int size;
 
@@ -384,7 +384,7 @@ static int gdm_wimax_ioctl_get_data(struct data_s *dst, 
struct data_s *src)
return 0;
 }
 
-static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct data_s *src)
+static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct udata_s *src)
 {
if (!src->size) {
dst->size = 0;
@@ -460,6 +460,7 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct 
ifreq *ifr, int cmd)
struct wm_req_s *req = (struct wm_req_s *)ifr;
struct nic *nic = netdev_priv(dev);
int ret;
+   void *fsm_buf;
 
if (cmd != SIOCWMIOCTL)
return -EOPNOTSUPP;
@@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct 
ifreq *ifr, int cmd)
/* NOTE: gdm_update_fsm should be called
 * before gdm_wimax_ioctl_set_data is called.
 */
-   gdm_update_fsm(dev,
-  req->data.buf);
+   fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
+   if (!fsm_buf)
+   return -ENOMEM;
+   if (copy_from_user(fsm_buf, req->data.buf,
+  sizeof(fsm_s))) {
+   kfree(fsm_buf);
+   return -EFAULT;
+   }
+   gdm_update_fsm(dev, fsm_buf);
+   kfree(fsm_buf);
}
ret = gdm_wimax_ioctl_set_data(
>sdk_data[req->data_id], >data);
diff --git a/drivers/staging/gdm72xx/wm_ioctl.h 
b/drivers/staging/gdm72xx/wm_ioctl.h
index ed8f649..631cb1d 100644
--- a/drivers/staging/gdm72xx/wm_ioctl.h
+++ b/drivers/staging/gdm72xx/wm_ioctl.h
@@ -78,13 +78,18 @@ struct data_s {
void*buf;
 };
 
+struct udata_s {
+   int size;
+   void __user *buf;
+};
+
 struct wm_req_s {
union {
char ifrn_name[IFNAMSIZ];
} ifr_ifrn;
unsigned short  cmd;
unsigned short  data_id;
-   struct data_s   data;
+   struct udata_s  data;
 
 /* NOTE: sizeof(struct wm_req_s) must be less than sizeof(struct ifreq). */
 };
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: gdm72xx: add userspace data struct

2015-12-10 Thread Dan Carpenter
On Thu, Dec 10, 2015 at 10:11:12AM +0100, Wim de With wrote:
> @@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, 
> struct ifreq *ifr, int cmd)
>   /* NOTE: gdm_update_fsm should be called
>* before gdm_wimax_ioctl_set_data is called.
>*/
> - gdm_update_fsm(dev,
> -req->data.buf);
> + fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
> + if (!fsm_buf)
> + return -ENOMEM;
> + if (copy_from_user(fsm_buf, req->data.buf,
> +sizeof(fsm_s))) {
> + kfree(fsm_buf);
> + return -EFAULT;
> + }
> + gdm_update_fsm(dev, fsm_buf);
> + kfree(fsm_buf);


No.  This change is a bug.

regards,
dan carpenter

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/2] staging: COMEDI: Added missing spaces at binary operators

2015-12-10 Thread Joe Perches
On Thu, 2015-12-10 at 15:57 +0100, Moritz König wrote:
> #define CR_AREF(a) (((a) >> 24)&0x03)

If you are going to fix these, it'd probably be better
to use spaces around the '&' too

#define CR_AREF(a) (((a) >> 24) & 0x03)

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] scsi: storvsc: Tighten up the interrupt path

2015-12-10 Thread K. Y. Srinivasan
On the interrupt path, we repeatedly establish the pointer to the
storvsc_device. Fix this.

Signed-off-by: K. Y. Srinivasan 
Reviewed-by: Long Li 
Tested-by: Alex Ng 
---
 drivers/scsi/storvsc_drv.c |   23 ---
 1 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 6f18e94..8ba9908 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -958,19 +958,16 @@ static void storvsc_handle_error(struct vmscsi_request 
*vm_srb,
 }
 
 
-static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
+static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request,
+  struct storvsc_device *stor_dev)
 {
struct scsi_cmnd *scmnd = cmd_request->cmd;
-   struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
struct scsi_sense_hdr sense_hdr;
struct vmscsi_request *vm_srb;
struct Scsi_Host *host;
-   struct storvsc_device *stor_dev;
-   struct hv_device *dev = host_dev->dev;
u32 payload_sz = cmd_request->payload_sz;
void *payload = cmd_request->payload;
 
-   stor_dev = get_in_stor_device(dev);
host = stor_dev->host;
 
vm_srb = _request->vstor_packet.vm_srb;
@@ -1000,14 +997,13 @@ static void storvsc_command_completion(struct 
storvsc_cmd_request *cmd_request)
kfree(payload);
 }
 
-static void storvsc_on_io_completion(struct hv_device *device,
+static void storvsc_on_io_completion(struct storvsc_device *stor_device,
  struct vstor_packet *vstor_packet,
  struct storvsc_cmd_request *request)
 {
-   struct storvsc_device *stor_device;
struct vstor_packet *stor_pkt;
+   struct hv_device *device = stor_device->device;
 
-   stor_device = hv_get_drvdata(device);
stor_pkt = >vstor_packet;
 
/*
@@ -1062,7 +1058,7 @@ static void storvsc_on_io_completion(struct hv_device 
*device,
stor_pkt->vm_srb.data_transfer_length =
vstor_packet->vm_srb.data_transfer_length;
 
-   storvsc_command_completion(request);
+   storvsc_command_completion(request, stor_device);
 
if (atomic_dec_and_test(_device->num_outstanding_req) &&
stor_device->drain_notify)
@@ -1071,21 +1067,19 @@ static void storvsc_on_io_completion(struct hv_device 
*device,
 
 }
 
-static void storvsc_on_receive(struct hv_device *device,
+static void storvsc_on_receive(struct storvsc_device *stor_device,
 struct vstor_packet *vstor_packet,
 struct storvsc_cmd_request *request)
 {
struct storvsc_scan_work *work;
-   struct storvsc_device *stor_device;
 
switch (vstor_packet->operation) {
case VSTOR_OPERATION_COMPLETE_IO:
-   storvsc_on_io_completion(device, vstor_packet, request);
+   storvsc_on_io_completion(stor_device, vstor_packet, request);
break;
 
case VSTOR_OPERATION_REMOVE_DEVICE:
case VSTOR_OPERATION_ENUMERATE_BUS:
-   stor_device = get_in_stor_device(device);
work = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
if (!work)
return;
@@ -1096,7 +1090,6 @@ static void storvsc_on_receive(struct hv_device *device,
break;
 
case VSTOR_OPERATION_FCHBA_DATA:
-   stor_device = get_in_stor_device(device);
cache_wwn(stor_device, vstor_packet);
fc_host_node_name(stor_device->host) = stor_device->node_name;
fc_host_port_name(stor_device->host) = stor_device->port_name;
@@ -1144,7 +1137,7 @@ static void storvsc_on_channel_callback(void *context)
vmscsi_size_delta));
complete(>wait_event);
} else {
-   storvsc_on_receive(device,
+   storvsc_on_receive(stor_device,
(struct vstor_packet *)packet,
request);
}
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging/rdma/hfi1: Fix for module parameter hdrq_entsize when it's 0

2015-12-10 Thread Stephen Rothwell
Hi Mike,

On Thu, 10 Dec 2015 16:02:49 -0500 Mike Marciniszyn 
 wrote:
>
> From: Sebastian Sanchez 

linux-nxt doesn't really need to be informed about random changes to
stuff in staging unless it fixes a linux-next specific problem.

-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH V2 02/10] Drivers: hv: utils: run polling callback always in interrupt context

2015-12-10 Thread KY Srinivasan


> -Original Message-
> From: Dexuan Cui
> Sent: Thursday, December 10, 2015 2:19 AM
> To: KY Srinivasan ; gre...@linuxfoundation.org; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; o...@aepfle.de;
> a...@canonical.com; vkuzn...@redhat.com; jasow...@redhat.com
> Subject: RE: [PATCH V2 02/10] Drivers: hv: utils: run polling callback always 
> in
> interrupt context
> 
> > -Original Message-
> > From: devel [mailto:driverdev-devel-boun...@linuxdriverproject.org] On
> Behalf
> > Of K. Y. Srinivasan
> > Sent: Friday, October 30, 2015 9:13
> > To: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> > de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> > vkuzn...@redhat.com; jasow...@redhat.com
> > Subject: [PATCH V2 02/10] Drivers: hv: utils: run polling callback always in
> > interrupt context
> >
> > From: Olaf Hering 
> >
> > All channel interrupts are bound to specific VCPUs in the guest
> > at the point channel is created. While currently, we invoke the
> > polling function on the correct CPU (the CPU to which the channel
> > is bound to) in some cases we may run the polling function in
> > a non-interrupt context. This  potentially can cause an issue as the
> > polling function can be interrupted by the channel callback function.
> > Fix the issue by running the polling function on the appropriate CPU
> > at interrupt level. Additional details of the issue being addressed by
> > this patch are given below:
> >
> > Currently hv_fcopy_onchannelcallback is called from interrupts and also
> > via the ->write function of hv_utils. Since the used global variables to
> > maintain state are not thread safe the state can get out of sync.
> > This affects the variable state as well as the channel inbound buffer.
> >
> > As suggested by KY adjust hv_poll_channel to always run the given
> > callback on the cpu which the channel is bound to. This avoids the need
> > for locking because all the util services are single threaded and only
> > one transaction is active at any given point in time.
> >
> > Additionally, remove the context variable, they will always be the same as
> > recv_channel.
> >
> > Signed-off-by: Olaf Hering 
> > Signed-off-by: K. Y. Srinivasan 
> > ---
> > V2: Added the check to catch unsolicited daemon writes - Vitaly
> >
> >  drivers/hv/hv_fcopy.c |   34 +-
> >  drivers/hv/hv_kvp.c   |   28 ++--
> >  drivers/hv/hv_snapshot.c  |   29 +++--
> >  drivers/hv/hyperv_vmbus.h |6 +-
> >  4 files changed, 35 insertions(+), 62 deletions(-)
> 
> (Sorry for not joining the discussion when the patch was firstly made)
> 
> It looks the patch has not been Greg's tree yet.
> 
> I have 2 questions about the patch:
> 
> 1. hv_poll_channel() is invoked in fcopy_handle_handshake(), but not in
> vss_handle_handshake() and kvp_handle_handshake().
> Why -- I guess we missed the vss/kvp cases somehow?
I will fix this.

> 
> 2.  With the patch, hv_fcopy_onchannelcallback() can be invoked in the
> tasklet (i.e., vmbus_on_event(). NB: local irq is enabled), and in the
> hard irq handler(the IPI handler, e.g.,
> fcopy_poll_wrapper() -> fcopy_poll_wrapper()).
> 
> Can the former be interrupted by the latter?
> e.g., when the callback is running in the tasklet on vCPU0,
> fcopy_timeout_func() or fcopy_on_msg() could send the IPI to
> vCPU0 from another vCPU.

Keep in mind that when the poll function is run, the state will not be
HVUTIL_READY. The state will be set to HVUTIL_READY in the IPI
handler. So, it is ok if the tasklet is interrupted by the IPI handler.

Regards,

K. Y

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v4 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-10 Thread Brian Norris
On Thu, Dec 10, 2015 at 08:59:45AM +0100, Boris Brezillon wrote:
> Unregister the NAND device from the NAND subsystem when removing a denali
> NAND controller, otherwise the MTD attached to the NAND device is still
> exposed by the MTD layer, and accesses to this device will likely crash
> the system.
> 
> Signed-off-by: Boris Brezillon 
> Cc:  #3.8+

Does this follow these rules, from
Documentation/stable_kernel_rules.txt?

 - It must be obviously correct and tested.

 - It must fix a real bug that bothers people (not a, "This could be a
   problem..." type thing).

> Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")
> ---
>  drivers/mtd/nand/denali.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
> index 67eb2be..8feece3 100644
> --- a/drivers/mtd/nand/denali.c
> +++ b/drivers/mtd/nand/denali.c
> @@ -1622,6 +1622,7 @@ EXPORT_SYMBOL(denali_init);
>  /* driver exit point */
>  void denali_remove(struct denali_nand_info *denali)
>  {
> + nand_release(>mtd);
>   denali_irq_cleanup(denali->irq, denali);
>   dma_unmap_single(denali->dev, denali->buf.dma_buf,
>denali->mtd.writesize + denali->mtd.oobsize,

It feels a bit odd to allow usage of MTD fields after it has been
unregistered. Maybe precompute this before the nand_release()?

Brian
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: goldfish: Coding Style Fix - spaces preferred around that '+'

2015-12-10 Thread Benjamin Young
>From 4b8ce6b3bd7effdfff2c95fbeb4a20cb93d5e9e5 Mon Sep 17 00:00:00 2001
From: Benjamin Young 
Date: Thu, 10 Dec 2015 17:31:00 -0500
Subject: [PATCH] staging: goldfish: Coding Style Fix - spaces preferred around
 that '+'

Helped improve coding style to make arithemethic easier to read

Signed-off-by: Benjamin Young 
---
 drivers/staging/goldfish/goldfish_audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/goldfish/goldfish_audio.c 
b/drivers/staging/goldfish/goldfish_audio.c
index b0927e4..f1e1838 100644
--- a/drivers/staging/goldfish/goldfish_audio.c
+++ b/drivers/staging/goldfish/goldfish_audio.c
@@ -63,7 +63,7 @@ struct goldfish_audio {
 #define AUDIO_READ(data, addr) (readl(data->reg_base + addr))
 #define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr))
 #define AUDIO_WRITE64(data, addr, addr2, x)\
-   (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base+addr2))
+   (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base + addr2))
 
 /*
  *  temporary variable used between goldfish_audio_probe() and
-- 
2.5.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] staging: gdm72xx: add userspace data struct

2015-12-10 Thread Wim de With
On Thu, Dec 10, 2015 at 02:44:45PM +, One Thousand Gnomes wrote:
> (except that you mean sizeof(struct fsm_s) and it doesn't compile at the
> moment!

Oops, sloppy mistake.

> data_s can just be modified to be __user. All uses of it follow that
> rule.

What do you mean? The data still needs to be copied from user space to kernel
space, if I'm not mistaken. And not all uses follow that rule, since in both
gdm_wimax_ioctl_get_data() and gdm_wimax_ioctl_set_data() it is used as both
the source and destination in the copy_from_user() and copy_to_user() call.

> All I think you need in this case is
> 
>   struct fsm_s fsm_buf;
> 
>   if (copy_from_user(_buf, req->data.buf,sizeof(buf))
>   return -EFAULT
>   gdm_update_fsm(_buf);

Do you mean sizeof(fsm_s)? I realize this would have been far simpler than my
overkill solution.

> If you are touching the structs it might be wise to fix the other
> problems with them notably the use of int. sizes when used are unsigned -
> and signed sizes are asking for errors. In fact if you look at the
> existing uses of the size checks they look deeply suspicious the moment
> anything malicious passes in negative numbers.

I would love to do that, but it is a bit outside the scope of this patch, so I
would rather safe this for another patch.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] staging: gdm72xx: add userspace data struct

2015-12-10 Thread One Thousand Gnomes
On Fri, 11 Dec 2015 00:47:38 +0100
Wim de With  wrote:

> On Thu, Dec 10, 2015 at 02:44:45PM +, One Thousand Gnomes wrote:
> > (except that you mean sizeof(struct fsm_s) and it doesn't compile at the
> > moment!
> 
> Oops, sloppy mistake.

Compile/test/send - even when in a hurry

> > data_s can just be modified to be __user. All uses of it follow that
> > rule.
> 
> What do you mean? The data still needs to be copied from user space to kernel
> space, if I'm not mistaken. And not all uses follow that rule, since in both
> gdm_wimax_ioctl_get_data() and gdm_wimax_ioctl_set_data() it is used as both
> the source and destination in the copy_from_user() and copy_to_user() call.

Good point I missed that.

> > All I think you need in this case is
> > 
> > struct fsm_s fsm_buf;
> > 
> > if (copy_from_user(_buf, req->data.buf,sizeof(buf))
> > return -EFAULT
> > gdm_update_fsm(_buf);
> 
> Do you mean sizeof(fsm_s)? I realize this would have been far simpler than my
> overkill solution.

Yes either sizeof(struct fsm_s) or sizeof(fsm_buf). The former is often
safer.

> > If you are touching the structs it might be wise to fix the other
> > problems with them notably the use of int. sizes when used are unsigned -
> > and signed sizes are asking for errors. In fact if you look at the
> > existing uses of the size checks they look deeply suspicious the moment
> > anything malicious passes in negative numbers.
> 
> I would love to do that, but it is a bit outside the scope of this patch, so I
> would rather safe this for another patch.

Absolutely right - it should be another patch

Alan
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/4] scsi: storvsc: Refactor the code in storvsc_channel_init()

2015-12-10 Thread K. Y. Srinivasan
The function storvsc_channel_init() repeatedly interacts with the host to
extract various channel properties. Refactor this code to eliminate code
repetition.

Signed-off-by: K. Y. Srinivasan 
Reviewed-by: Long Li 
Tested-by: Alex Ng 
---
 drivers/scsi/storvsc_drv.c |  155 
 1 files changed, 57 insertions(+), 98 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index b94d471..6f18e94 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -721,29 +721,16 @@ static void cache_wwn(struct storvsc_device *stor_device,
}
 }
 
-static int storvsc_channel_init(struct hv_device *device, bool is_fc)
+static int storvsc_execute_vstor_op(struct hv_device *device,
+   struct storvsc_cmd_request *request,
+   bool status_check)
 {
-   struct storvsc_device *stor_device;
-   struct storvsc_cmd_request *request;
struct vstor_packet *vstor_packet;
-   int ret, t, i;
-   int max_chns;
-   bool process_sub_channels = false;
-
-   stor_device = get_out_stor_device(device);
-   if (!stor_device)
-   return -ENODEV;
+   int ret, t;
 
-   request = _device->init_request;
vstor_packet = >vstor_packet;
 
-   /*
-* Now, initiate the vsc/vsp initialization protocol on the open
-* channel
-*/
-   memset(request, 0, sizeof(struct storvsc_cmd_request));
init_completion(>wait_event);
-   vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
 
ret = vmbus_sendpacket(device->channel, vstor_packet,
@@ -753,27 +740,62 @@ static int storvsc_channel_init(struct hv_device *device, 
bool is_fc)
   VM_PKT_DATA_INBAND,
   VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
if (ret != 0)
-   goto cleanup;
+   goto done;
 
t = wait_for_completion_timeout(>wait_event, 5*HZ);
if (t == 0) {
ret = -ETIMEDOUT;
-   goto cleanup;
+   goto done;
}
 
+   if (!status_check)
+   goto done;
+
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
vstor_packet->status != 0) {
ret = -EINVAL;
-   goto cleanup;
+   goto done;
}
 
+done:
+   return ret;
+}
+
+static int storvsc_channel_init(struct hv_device *device, bool is_fc)
+{
+   struct storvsc_device *stor_device;
+   struct storvsc_cmd_request *request;
+   struct vstor_packet *vstor_packet;
+   int ret, i;
+   int max_chns;
+   bool process_sub_channels = false;
+
+   stor_device = get_out_stor_device(device);
+   if (!stor_device)
+   return -ENODEV;
+
+   request = _device->init_request;
+   vstor_packet = >vstor_packet;
+
+   /*
+* Now, initiate the vsc/vsp initialization protocol on the open
+* channel
+*/
+   memset(request, 0, sizeof(struct storvsc_cmd_request));
+   vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
+   ret = storvsc_execute_vstor_op(device, request, true);
+   if (ret)
+   goto cleanup;
+
+   /*
+* Query host supported protocol version.
+*/
 
for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
/* reuse the packet for version range supported */
memset(vstor_packet, 0, sizeof(struct vstor_packet));
vstor_packet->operation =
VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
-   vstor_packet->flags = REQUEST_COMPLETION_FLAG;
 
vstor_packet->version.major_minor =
vmstor_protocols[i].protocol_version;
@@ -783,20 +805,9 @@ static int storvsc_channel_init(struct hv_device *device, 
bool is_fc)
 */
vstor_packet->version.revision = 0;
 
-   ret = vmbus_sendpacket(device->channel, vstor_packet,
-  (sizeof(struct vstor_packet) -
-   vmscsi_size_delta),
-  (unsigned long)request,
-  VM_PKT_DATA_INBAND,
-  VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
-   if (ret != 0)
-   goto cleanup;
-
-   t = wait_for_completion_timeout(>wait_event, 5*HZ);
-   if (t == 0) {
-   ret = -ETIMEDOUT;
+   ret = storvsc_execute_vstor_op(device, request, false);
+   if (ret)
goto cleanup;
-   }
 
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO) {
ret 

[PATCH 1/4] scsi: storvsc: Fix a bug in the layout of the hv_fc_wwn_packet

2015-12-10 Thread K. Y. Srinivasan
The hv_fc_wwn_packet is exchanged over vmbus. Make the definition in Linux match
the Window's definition.

Signed-off-by: K. Y. Srinivasan 
Reviewed-by: Long Li 
Tested-by: Alex Ng 
---
 drivers/scsi/storvsc_drv.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index c41f674..00bb4bd 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -92,9 +92,8 @@ enum vstor_packet_operation {
  */
 
 struct hv_fc_wwn_packet {
-   boolprimary_active;
-   u8  reserved1;
-   u8  reserved2;
+   u8  primary_active;
+   u8  reserved1[3];
u8  primary_port_wwn[8];
u8  primary_node_wwn[8];
u8  secondary_port_wwn[8];
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/4] scsi: storvsc: Properly support FC hosts

2015-12-10 Thread K. Y. Srinivasan
Properly support FC hosts. Additional cleanup patches are also
included.

K. Y. Srinivasan (4):
  scsi: storvsc: Fix a bug in the layout of the hv_fc_wwn_packet
  scsi: storvsc: Properly support Fibre Channel devices
  scsi: storvsc: Refactor the code in storvsc_channel_init()
  scsi: storvsc: Tighten up the interrupt path

 drivers/scsi/storvsc_drv.c |  235 ++--
 1 files changed, 138 insertions(+), 97 deletions(-)

-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/4] scsi: storvsc: Properly support Fibre Channel devices

2015-12-10 Thread K. Y. Srinivasan
For FC devices managed by this driver, atttach the appropriate transport
template. This will allow us to create the appropriate sysfs files for
these devices. With this we can publish the wwn for both the port and the node.

Signed-off-by: K. Y. Srinivasan 
Reviewed-by: Long Li 
Tested-by: Alex Ng 
---
 drivers/scsi/storvsc_drv.c |  100 +--
 1 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 00bb4bd..b94d471 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * All wire protocol details (storage protocol between the guest and the host)
@@ -397,6 +398,7 @@ static int storvsc_timeout = 180;
 
 static int msft_blist_flags = BLIST_TRY_VPD_PAGES;
 
+static struct scsi_transport_template *fc_transport_template;
 
 static void storvsc_on_channel_callback(void *context);
 
@@ -456,6 +458,11 @@ struct storvsc_device {
/* Used for vsc/vsp channel reset process */
struct storvsc_cmd_request init_request;
struct storvsc_cmd_request reset_request;
+   /*
+* Currently active port and node names for FC devices.
+*/
+   u64 node_name;
+   u64 port_name;
 };
 
 struct hv_host_device {
@@ -695,7 +702,26 @@ static void  handle_multichannel_storage(struct hv_device 
*device, int max_chns)
vmbus_are_subchannels_present(device->channel);
 }
 
-static int storvsc_channel_init(struct hv_device *device)
+static void cache_wwn(struct storvsc_device *stor_device,
+ struct vstor_packet *vstor_packet)
+{
+   /*
+* Cache the currently active port and node ww names.
+*/
+   if (vstor_packet->wwn_packet.primary_active) {
+   stor_device->node_name =
+   wwn_to_u64(vstor_packet->wwn_packet.primary_node_wwn);
+   stor_device->port_name =
+   wwn_to_u64(vstor_packet->wwn_packet.primary_port_wwn);
+   } else {
+   stor_device->node_name =
+   wwn_to_u64(vstor_packet->wwn_packet.secondary_node_wwn);
+   stor_device->port_name =
+   wwn_to_u64(vstor_packet->wwn_packet.secondary_port_wwn);
+   }
+}
+
+static int storvsc_channel_init(struct hv_device *device, bool is_fc)
 {
struct storvsc_device *stor_device;
struct storvsc_cmd_request *request;
@@ -837,6 +863,40 @@ static int storvsc_channel_init(struct hv_device *device)
stor_device->max_transfer_bytes =
vstor_packet->storage_channel_properties.max_transfer_bytes;
 
+   if (!is_fc)
+   goto done;
+
+   memset(vstor_packet, 0, sizeof(struct vstor_packet));
+   vstor_packet->operation = VSTOR_OPERATION_FCHBA_DATA;
+   vstor_packet->flags = REQUEST_COMPLETION_FLAG;
+
+   ret = vmbus_sendpacket(device->channel, vstor_packet,
+  (sizeof(struct vstor_packet) -
+  vmscsi_size_delta),
+  (unsigned long)request,
+  VM_PKT_DATA_INBAND,
+  VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+
+   if (ret != 0)
+   goto cleanup;
+
+   t = wait_for_completion_timeout(>wait_event, 5*HZ);
+   if (t == 0) {
+   ret = -ETIMEDOUT;
+   goto cleanup;
+   }
+
+   if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
+   vstor_packet->status != 0)
+   goto cleanup;
+
+   /*
+* Cache the currently active port and node ww names.
+*/
+   cache_wwn(stor_device, vstor_packet);
+
+done:
+
memset(vstor_packet, 0, sizeof(struct vstor_packet));
vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
@@ -1076,6 +1136,12 @@ static void storvsc_on_receive(struct hv_device *device,
schedule_work(>work);
break;
 
+   case VSTOR_OPERATION_FCHBA_DATA:
+   stor_device = get_in_stor_device(device);
+   cache_wwn(stor_device, vstor_packet);
+   fc_host_node_name(stor_device->host) = stor_device->node_name;
+   fc_host_port_name(stor_device->host) = stor_device->port_name;
+   break;
default:
break;
}
@@ -1131,7 +1197,8 @@ static void storvsc_on_channel_callback(void *context)
return;
 }
 
-static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size)
+static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size,
+ bool is_fc)
 {
struct vmstorage_channel_properties props;
int ret;
@@ -1148,7 +1215,7 @@ static int storvsc_connect_to_vsp(struct 

[PATCH] staging: goldfish: Coding Style Fix Comparison to NULL could

2015-12-10 Thread Benjamin Young
>From f279a9e98b35301690abb39271367ecb0f611aff Mon Sep 17 00:00:00 2001
From: Benjamin Young 
Date: Thu, 10 Dec 2015 17:35:33 -0500
Subject: [PATCH] staging: goldfish: Coding Style Fix Comparison to NULL could
 be written "!r"

Fixed coding style for null comparisons in goldfish_audio.c to be more 
consistant
with the rest of the kernel coding style

Signed-off-by: Benjamin Young 
---
 drivers/staging/goldfish/goldfish_audio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/goldfish/goldfish_audio.c 
b/drivers/staging/goldfish/goldfish_audio.c
index f1e1838..364fdcd 100644
--- a/drivers/staging/goldfish/goldfish_audio.c
+++ b/drivers/staging/goldfish/goldfish_audio.c
@@ -280,12 +280,12 @@ static int goldfish_audio_probe(struct platform_device 
*pdev)
platform_set_drvdata(pdev, data);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   if (r == NULL) {
+   if (!r) {
dev_err(>dev, "platform_get_resource failed\n");
return -ENODEV;
}
data->reg_base = devm_ioremap(>dev, r->start, PAGE_SIZE);
-   if (data->reg_base == NULL)
+   if (!data->reg_base)
return -ENOMEM;
 
data->irq = platform_get_irq(pdev, 0);
@@ -295,7 +295,7 @@ static int goldfish_audio_probe(struct platform_device 
*pdev)
}
data->buffer_virt = dmam_alloc_coherent(>dev,
COMBINED_BUFFER_SIZE, _addr, GFP_KERNEL);
-   if (data->buffer_virt == NULL) {
+   if (!data->buffer_virt) {
dev_err(>dev, "allocate buffer failed\n");
return -ENOMEM;
}
-- 
2.5.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: goldfish: Coding Style Fix Comparison to NULL could

2015-12-10 Thread Benjamin Young
>From 4b8ce6b3bd7effdfff2c95fbeb4a20cb93d5e9e5 Mon Sep 17 00:00:00 2001
From: Benjamin Young 
Date: Thu, 10 Dec 2015 17:31:00 -0500
Subject: [PATCH] staging: goldfish: Coding Style Fix - spaces preferred around
 that '+'

Helped improve coding style to make arithemethic easier to read

Signed-off-by: Benjamin Young 
---
 drivers/staging/goldfish/goldfish_audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/goldfish/goldfish_audio.c 
b/drivers/staging/goldfish/goldfish_audio.c
index b0927e4..f1e1838 100644
--- a/drivers/staging/goldfish/goldfish_audio.c
+++ b/drivers/staging/goldfish/goldfish_audio.c
@@ -63,7 +63,7 @@ struct goldfish_audio {
 #define AUDIO_READ(data, addr) (readl(data->reg_base + addr))
 #define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr))
 #define AUDIO_WRITE64(data, addr, addr2, x)\
-   (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base+addr2))
+   (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base + addr2))
 
 /*
  *  temporary variable used between goldfish_audio_probe() and
-- 
2.5.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: gdm72xx: add userspace data struct

2015-12-10 Thread Dan Carpenter
On Thu, Dec 10, 2015 at 10:42:14AM +0100, Wim de With wrote:
> On 10-12-2015 10:37, Dan Carpenter wrote:
> > On Thu, Dec 10, 2015 at 10:11:12AM +0100, Wim de With wrote:
> >> @@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, 
> >> struct ifreq *ifr, int cmd)
> >>/* NOTE: gdm_update_fsm should be called
> >> * before gdm_wimax_ioctl_set_data is called.
> >> */
> >> -  gdm_update_fsm(dev,
> >> - req->data.buf);
> >> +  fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
> >> +  if (!fsm_buf)
> >> +  return -ENOMEM;
> >> +  if (copy_from_user(fsm_buf, req->data.buf,
> >> + sizeof(fsm_s))) {
> >> +  kfree(fsm_buf);
> >> +  return -EFAULT;
> >> +  }
> >> +  gdm_update_fsm(dev, fsm_buf);
> >> +  kfree(fsm_buf);
> > 
> > 
> > No.  This change is a bug.
> > 
> > regards,
> > dan carpenter
> > 
> 
> But what if I just keep it as:
> 
>   gdm_update_fsm(dev, req->data.buf)
> 
> Then it would just trust a __user pointer right?

I appologize, I didn't read the patch carefully.  This is a bugfix.  Can
you resend the patch with a better patch description where you replace
the last paragraph and say:

Once I updated the Sparse annotations, I noticed a bug in
gdm_wimax_ioctl() where we pass a user space pointer to gdm_update_fsm()
which dereferences it.  I fixed this.

regards,
dan carpenter
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2] staging: gdm72xx: add userspace data struct

2015-12-10 Thread Wim de With
This fixes the sparse warnings about dereferencing a userspace pointer.

Once I updated the sparse annotations, I noticed a bug in
gdm_wimax_ioctl() where we pass a user space pointer to gdm_update_fsm()
which dereferences it. I fixed this.

Signed-off-by: Wim de With 
---
 drivers/staging/gdm72xx/gdm_wimax.c | 17 +
 drivers/staging/gdm72xx/wm_ioctl.h  |  7 ++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c 
b/drivers/staging/gdm72xx/gdm_wimax.c
index d9ddced..16eac61 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -368,7 +368,7 @@ static void kdelete(void **buf)
}
 }
 
-static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src)
+static int gdm_wimax_ioctl_get_data(struct udata_s *dst, struct data_s *src)
 {
int size;
 
@@ -384,7 +384,7 @@ static int gdm_wimax_ioctl_get_data(struct data_s *dst, 
struct data_s *src)
return 0;
 }
 
-static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct data_s *src)
+static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct udata_s *src)
 {
if (!src->size) {
dst->size = 0;
@@ -460,6 +460,7 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct 
ifreq *ifr, int cmd)
struct wm_req_s *req = (struct wm_req_s *)ifr;
struct nic *nic = netdev_priv(dev);
int ret;
+   void *fsm_buf;
 
if (cmd != SIOCWMIOCTL)
return -EOPNOTSUPP;
@@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct 
ifreq *ifr, int cmd)
/* NOTE: gdm_update_fsm should be called
 * before gdm_wimax_ioctl_set_data is called.
 */
-   gdm_update_fsm(dev,
-  req->data.buf);
+   fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
+   if (!fsm_buf)
+   return -ENOMEM;
+   if (copy_from_user(fsm_buf, req->data.buf,
+  sizeof(fsm_s))) {
+   kfree(fsm_buf);
+   return -EFAULT;
+   }
+   gdm_update_fsm(dev, fsm_buf);
+   kfree(fsm_buf);
}
ret = gdm_wimax_ioctl_set_data(
>sdk_data[req->data_id], >data);
diff --git a/drivers/staging/gdm72xx/wm_ioctl.h 
b/drivers/staging/gdm72xx/wm_ioctl.h
index ed8f649..631cb1d 100644
--- a/drivers/staging/gdm72xx/wm_ioctl.h
+++ b/drivers/staging/gdm72xx/wm_ioctl.h
@@ -78,13 +78,18 @@ struct data_s {
void*buf;
 };
 
+struct udata_s {
+   int size;
+   void __user *buf;
+};
+
 struct wm_req_s {
union {
char ifrn_name[IFNAMSIZ];
} ifr_ifrn;
unsigned short  cmd;
unsigned short  data_id;
-   struct data_s   data;
+   struct udata_s  data;
 
 /* NOTE: sizeof(struct wm_req_s) must be less than sizeof(struct ifreq). */
 };
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH V2 02/10] Drivers: hv: utils: run polling callback always in interrupt context

2015-12-10 Thread Dexuan Cui
> -Original Message-
> From: devel [mailto:driverdev-devel-boun...@linuxdriverproject.org] On Behalf
> Of K. Y. Srinivasan
> Sent: Friday, October 30, 2015 9:13
> To: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> vkuzn...@redhat.com; jasow...@redhat.com
> Subject: [PATCH V2 02/10] Drivers: hv: utils: run polling callback always in
> interrupt context
> 
> From: Olaf Hering 
> 
> All channel interrupts are bound to specific VCPUs in the guest
> at the point channel is created. While currently, we invoke the
> polling function on the correct CPU (the CPU to which the channel
> is bound to) in some cases we may run the polling function in
> a non-interrupt context. This  potentially can cause an issue as the
> polling function can be interrupted by the channel callback function.
> Fix the issue by running the polling function on the appropriate CPU
> at interrupt level. Additional details of the issue being addressed by
> this patch are given below:
> 
> Currently hv_fcopy_onchannelcallback is called from interrupts and also
> via the ->write function of hv_utils. Since the used global variables to
> maintain state are not thread safe the state can get out of sync.
> This affects the variable state as well as the channel inbound buffer.
> 
> As suggested by KY adjust hv_poll_channel to always run the given
> callback on the cpu which the channel is bound to. This avoids the need
> for locking because all the util services are single threaded and only
> one transaction is active at any given point in time.
> 
> Additionally, remove the context variable, they will always be the same as
> recv_channel.
> 
> Signed-off-by: Olaf Hering 
> Signed-off-by: K. Y. Srinivasan 
> ---
>   V2: Added the check to catch unsolicited daemon writes - Vitaly
> 
>  drivers/hv/hv_fcopy.c |   34 +-
>  drivers/hv/hv_kvp.c   |   28 ++--
>  drivers/hv/hv_snapshot.c  |   29 +++--
>  drivers/hv/hyperv_vmbus.h |6 +-
>  4 files changed, 35 insertions(+), 62 deletions(-)

(Sorry for not joining the discussion when the patch was firstly made)

It looks the patch has not been Greg's tree yet.

I have 2 questions about the patch:

1. hv_poll_channel() is invoked in fcopy_handle_handshake(), but not in
vss_handle_handshake() and kvp_handle_handshake().
Why -- I guess we missed the vss/kvp cases somehow?

2.  With the patch, hv_fcopy_onchannelcallback() can be invoked in the
tasklet (i.e., vmbus_on_event(). NB: local irq is enabled), and in the
hard irq handler(the IPI handler, e.g., 
fcopy_poll_wrapper() -> fcopy_poll_wrapper()).

Can the former be interrupted by the latter?
e.g., when the callback is running in the tasklet on vCPU0,
fcopy_timeout_func() or fcopy_on_msg() could send the IPI to
vCPU0 from another vCPU.

Thanks,
-- Dexuan
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v10 0/7] PCI: hv: New paravirtual PCI front-end for Hyper-V VMs

2015-12-10 Thread jakeo
From: Jake Oshins 

This version of the patch series removes warning when compiling x86
32-bit while still making it build cleanly for x64.

First, export functions that allow correlating Hyper-V virtual processors
and Linux cpus, along with the means for invoking a hypercall that targets
interrupts at chosen vectors on specific cpus.

Second, mark various parts of IRQ domain related code as exported, so that
this PCI front-end can implement an IRQ domain as part of a module.  (The
alternative would be to pull all tyhis into the kernel, which would pull
in a lot of other Hyper-V related code, as this IRQ domain depends on
vmbus.ko.)

Third, modify PCI so that new root PCI buses can be marked with an associated
fwnode_handle, and so that root PCI buses can look up their associated IRQ
domain by that handle.

Fourth, introduce a new driver, hv_pcifront, which exposes root PCI buses in
a Hyper-V VM.  These root PCI buses expose real PCIe device, or PCI Virtual
Functions.


Jake Oshins (7):
  drivers:hv: Export a function that maps Linux CPU num onto Hyper-V
proc num
  drivers:hv: Export hv_do_hypercall()
  PCI: Make it possible to implement a PCI MSI IRQ Domain in a module.
  PCI: Add fwnode_handle to pci_sysdata
  PCI: irqdomain: Look up IRQ domain by fwnode_handle
  drivers:hv: Define the channel type of Hyper-V PCI Express
pass-through
  PCI: hv: New paravirtual PCI front-end for Hyper-V VMs

 MAINTAINERS|1 +
 arch/x86/include/asm/msi.h |6 +
 arch/x86/include/asm/pci.h |   15 +
 arch/x86/kernel/apic/msi.c |8 +-
 arch/x86/kernel/apic/vector.c  |2 +
 drivers/hv/hv.c|   20 +-
 drivers/hv/hyperv_vmbus.h  |2 +-
 drivers/hv/vmbus_drv.c |   17 +
 drivers/pci/Kconfig|7 +
 drivers/pci/host/Makefile  |1 +
 drivers/pci/host/hv_pcifront.c | 2249 
 drivers/pci/msi.c  |4 +
 drivers/pci/probe.c|   15 +
 include/linux/hyperv.h |   14 +
 include/linux/pci.h|4 +
 kernel/irq/chip.c  |1 +
 kernel/irq/irqdomain.c |4 +
 17 files changed, 2356 insertions(+), 14 deletions(-)
 create mode 100644 drivers/pci/host/hv_pcifront.c

-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v10 4/7] PCI: Add fwnode_handle to pci_sysdata

2015-12-10 Thread jakeo
From: Jake Oshins 

This patch adds an fwnode_handle to struct pci_sysdata, which is
used by the next patch in the series when trying to locate an
IRQ domain associated with a root PCI bus.

Signed-off-by: Jake Oshins 
---
 arch/x86/include/asm/pci.h | 15 +++
 drivers/pci/probe.c|  1 +
 include/linux/pci.h|  4 
 3 files changed, 20 insertions(+)

diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h
index 4625943..6fc3c7c 100644
--- a/arch/x86/include/asm/pci.h
+++ b/arch/x86/include/asm/pci.h
@@ -20,6 +20,9 @@ struct pci_sysdata {
 #ifdef CONFIG_X86_64
void*iommu; /* IOMMU private data */
 #endif
+#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
+   void*fwnode;/* IRQ domain for MSI assignment */
+#endif
 };
 
 extern int pci_routeirq;
@@ -32,6 +35,7 @@ extern int noioapicreroute;
 static inline int pci_domain_nr(struct pci_bus *bus)
 {
struct pci_sysdata *sd = bus->sysdata;
+
return sd->domain;
 }
 
@@ -41,6 +45,17 @@ static inline int pci_proc_domain(struct pci_bus *bus)
 }
 #endif
 
+#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
+static inline void *_pci_root_bus_fwnode(struct pci_bus *bus)
+{
+   struct pci_sysdata *sd = bus->sysdata;
+
+   return sd->fwnode;
+}
+
+#define pci_root_bus_fwnode_pci_root_bus_fwnode
+#endif
+
 /* Can be used to override the logic in pci_scan_bus for skipping
already-configured bus numbers - to be used for buggy BIOSes
or architectures with incomplete PCI setup by the loader */
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index edb1984..750f907 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "pci.h"
 
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 6ae25aa..b414422 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1517,6 +1517,10 @@ static inline int pci_get_new_domain_nr(void) { return 
-ENOSYS; }
 
 #include 
 
+#ifndef pci_root_bus_fwnode
+#define pci_root_bus_fwnode(bus)   ((void)(bus), NULL)
+#endif
+
 /* these helpers provide future and backwards compatibility
  * for accessing popular PCI BAR info */
 #define pci_resource_start(dev, bar)   ((dev)->resource[(bar)].start)
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v10 6/7] drivers:hv: Define the channel type of Hyper-V PCI Express pass-through

2015-12-10 Thread jakeo
From: Jake Oshins 

This defines the channel type for PCI front-ends in Hyper-V VMs.

Signed-off-by: Jake Oshins 
---
 include/linux/hyperv.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 24d0b65..c9a9eed 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -1141,6 +1141,17 @@ u64 hv_do_hypercall(u64 control, void *input, void 
*output);
}
 
 /*
+ * PCI Express Pass Through
+ * {44C4F61D--4400-9D52-802E27EDE19F}
+ */
+
+#define HV_PCIE_GUID \
+   .guid = { \
+   0x1D, 0xF6, 0xC4, 0x44, 0x44, 0x44, 0x00, 0x44, \
+   0x9D, 0x52, 0x80, 0x2E, 0x27, 0xED, 0xE1, 0x9F \
+   }
+
+/*
  * Common header for Hyper-V ICs
  */
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v10 5/7] PCI: irqdomain: Look up IRQ domain by fwnode_handle

2015-12-10 Thread jakeo
From: Jake Oshins 

This patch adds a second way of finding an IRQ domain associated with
a root PCI bus.  After looking to see if one can be found through
the OF tree, it attempts to look up the IRQ domain through an
fwnode_handle stored in the pci_sysdata struct.

Signed-off-by: Jake Oshins 
---
 drivers/pci/probe.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 750f907..c6369dd 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -674,6 +674,20 @@ static struct irq_domain 
*pci_host_bridge_msi_domain(struct pci_bus *bus)
 */
d = pci_host_bridge_of_msi_domain(bus);
 
+#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
+   /*
+* If no IRQ domain was found via the OF tree, try looking it up
+* directly through the fwnode_handle.
+*/
+   if (!d) {
+   struct fwnode_handle *fwnode = pci_root_bus_fwnode(bus);
+
+   if (fwnode)
+   d = irq_find_matching_fwnode(fwnode,
+DOMAIN_BUS_PCI_MSI);
+   }
+#endif
+
return d;
 }
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Fixed coding style problems based on checkpatch.pl for goldfish_audio.c

2015-12-10 Thread Benjamin Young
On Thu, Dec 10, 2015 at 12:43:19PM +0530, Sudip Mukherjee wrote:
> On Wed, Dec 09, 2015 at 03:46:02PM -0800, Benjamin Young wrote:
> > From f18a3e5f155f5258d2d19ac6b56bfaafa2ad470b Mon Sep 17 00:00:00 2001
> > From: Benjamin Young 
> > Date: Wed, 9 Dec 2015 13:45:00 -0800
> > Subject: [PATCH] Fixed coding style problems based on checkpatch.pl for
> >  goldfish_audio.c
> 
> This should not be here.
> You have not given in commit message and you are doing multiple changes
> in this patch. Please split them into separate patch, each patch doing
> only a single type of change.
> 
> regards
> sudip

Thanks Sudip I will fix this by creating two new patches.
One for the comparison to null checks and the other for space between operators.

Was there anything else which I could improve on for this commit?

Thanks,
Benjamin
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v4 38/58] mtd: nand: s3c2410: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Krzysztof Kozlowski
On 10.12.2015 17:00, Boris Brezillon wrote:
> struct nand_chip now embeds an mtd device. Make use of this mtd instance.
> 
> Signed-off-by: Boris Brezillon 
> ---
> Changes generated with the following coccinelle script
> 
> --->8---
> virtual patch
> 
> @fix1@
> identifier __chipfield, __mtdfield;
> type __type;
> @@
> (
>   __type {
>   ...
>   struct nand_chip __chipfield;
>   ...
> - struct mtd_info __mtdfield;
>   ...
>   };
> |
>   __type {
>   ...
> - struct mtd_info __mtdfield;
>   ...
>   struct nand_chip __chipfield;
>   ...
>   };
> )
> 
> @fix2 depends on fix1@
> identifier fix1.__chipfield, fix1.__mtdfield;
> identifier __subfield;
> type fix1.__type;
> __type *__priv;
> @@
> (
> - __priv->__mtdfield.__subfield
> + nand_to_mtd(&__priv->__chipfield)->__subfield
> |
> - &(__priv->__mtdfield)
> + nand_to_mtd(&__priv->__chipfield)
> )
> --->8---
> ---
>  drivers/mtd/nand/s3c2410.c | 23 ++-
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 

Looks correct:

Reviewed-by: Krzysztof Kozlowski 

Best regards,
Krzysztof


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v10 4/7] PCI: Add fwnode_handle to pci_sysdata

2015-12-10 Thread Marc Zyngier
On 10/12/15 17:53, ja...@microsoft.com wrote:
> From: Jake Oshins 
> 
> This patch adds an fwnode_handle to struct pci_sysdata, which is
> used by the next patch in the series when trying to locate an
> IRQ domain associated with a root PCI bus.
> 
> Signed-off-by: Jake Oshins 
> ---
>  arch/x86/include/asm/pci.h | 15 +++
>  drivers/pci/probe.c|  1 +
>  include/linux/pci.h|  4 
>  3 files changed, 20 insertions(+)
> 
> diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h
> index 4625943..6fc3c7c 100644
> --- a/arch/x86/include/asm/pci.h
> +++ b/arch/x86/include/asm/pci.h
> @@ -20,6 +20,9 @@ struct pci_sysdata {
>  #ifdef CONFIG_X86_64
>   void*iommu; /* IOMMU private data */
>  #endif
> +#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
> + void*fwnode;/* IRQ domain for MSI assignment */
> +#endif
>  };
>  
>  extern int pci_routeirq;
> @@ -32,6 +35,7 @@ extern int noioapicreroute;
>  static inline int pci_domain_nr(struct pci_bus *bus)
>  {
>   struct pci_sysdata *sd = bus->sysdata;
> +
>   return sd->domain;
>  }
>  
> @@ -41,6 +45,17 @@ static inline int pci_proc_domain(struct pci_bus *bus)
>  }
>  #endif
>  
> +#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
> +static inline void *_pci_root_bus_fwnode(struct pci_bus *bus)
> +{
> + struct pci_sysdata *sd = bus->sysdata;
> +
> + return sd->fwnode;
> +}
> +
> +#define pci_root_bus_fwnode  _pci_root_bus_fwnode
> +#endif
> +
>  /* Can be used to override the logic in pci_scan_bus for skipping
> already-configured bus numbers - to be used for buggy BIOSes
> or architectures with incomplete PCI setup by the loader */
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index edb1984..750f907 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -15,6 +15,7 @@
>  #include 
>  #include 
>  #include 
> +#include 

Nit: this should be with patch 5, but that doesn't hurt. I don't think
you need to respin the series for this.

>  #include 
>  #include "pci.h"
>  
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 6ae25aa..b414422 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1517,6 +1517,10 @@ static inline int pci_get_new_domain_nr(void) { return 
> -ENOSYS; }
>  
>  #include 
>  
> +#ifndef pci_root_bus_fwnode
> +#define pci_root_bus_fwnode(bus) ((void)(bus), NULL)
> +#endif
> +
>  /* these helpers provide future and backwards compatibility
>   * for accessing popular PCI BAR info */
>  #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
> 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 172/182] staging: vme: use gpiochip data pointer

2015-12-10 Thread Martyn Welch



On 09/12/15 13:50, Linus Walleij wrote:

This makes the driver use the data pointer added to the gpio_chip
to store a pointer to the state container instead of relying on
container_of().

Cc: Greg Kroah-Hartman 
Cc: Martyn Welch 
Cc: Manohar Vanga 
Cc: de...@driverdev.osuosl.org
Signed-off-by: Linus Walleij 


Signed-of-by: Martyn Welch 


---
Greg, please ACK this so I can take this through the GPIO tree.
---
  drivers/staging/vme/devices/vme_pio2_gpio.c | 17 ++---
  1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_pio2_gpio.c 
b/drivers/staging/vme/devices/vme_pio2_gpio.c
index 77901b345a71..a2b740ab7ffe 100644
--- a/drivers/staging/vme/devices/vme_pio2_gpio.c
+++ b/drivers/staging/vme/devices/vme_pio2_gpio.c
@@ -17,7 +17,7 @@
  #include 
  #include 
  #include 
-#include 
+#include 
  #include 
  #include 
  
@@ -25,16 +25,11 @@
  
  static const char driver_name[] = "pio2_gpio";
  
-static struct pio2_card *gpio_to_pio2_card(struct gpio_chip *chip)

-{
-   return container_of(chip, struct pio2_card, gc);
-}
-
  static int pio2_gpio_get(struct gpio_chip *chip, unsigned int offset)
  {
u8 reg;
int retval;
-   struct pio2_card *card = gpio_to_pio2_card(chip);
+   struct pio2_card *card = gpiochip_get_data(chip);
  
  	if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == OUTPUT) |

(card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) {
@@ -72,7 +67,7 @@ static void pio2_gpio_set(struct gpio_chip *chip, unsigned 
int offset,
  {
u8 reg;
int retval;
-   struct pio2_card *card = gpio_to_pio2_card(chip);
+   struct pio2_card *card = gpiochip_get_data(chip);
  
  	if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == INPUT) |

(card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) {
@@ -102,7 +97,7 @@ static void pio2_gpio_set(struct gpio_chip *chip, unsigned 
int offset,
  static int pio2_gpio_dir_in(struct gpio_chip *chip, unsigned offset)
  {
int data;
-   struct pio2_card *card = gpio_to_pio2_card(chip);
+   struct pio2_card *card = gpiochip_get_data(chip);
  
  	if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == OUTPUT) |

(card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) {
@@ -121,7 +116,7 @@ static int pio2_gpio_dir_in(struct gpio_chip *chip, 
unsigned offset)
  static int pio2_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int 
value)
  {
int data;
-   struct pio2_card *card = gpio_to_pio2_card(chip);
+   struct pio2_card *card = gpiochip_get_data(chip);
  
  	if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == INPUT) |

(card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) {
@@ -207,7 +202,7 @@ int pio2_gpio_init(struct pio2_card *card)
card->gc.set = pio2_gpio_set;
  
  	/* This function adds a memory mapped GPIO chip */

-   retval = gpiochip_add(&(card->gc));
+   retval = gpiochip_add_data(&(card->gc), card);
if (retval) {
dev_err(>vdev->dev, "Unable to register GPIO\n");
kfree(card->gc.label);


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH V2 02/10] Drivers: hv: utils: run polling callback always in interrupt context

2015-12-10 Thread Dexuan Cui
> -Original Message-
> From: KY Srinivasan
> Sent: Friday, December 11, 2015 7:23
> > It looks the patch has not been Greg's tree yet.
> >
> > I have 2 questions about the patch:
> >
> > 1. hv_poll_channel() is invoked in fcopy_handle_handshake(), but not in
> > vss_handle_handshake() and kvp_handle_handshake().
> > Why -- I guess we missed the vss/kvp cases somehow?
> I will fix this.

Thanks, KY!
BTW, I fixed another small issue by https://lkml.org/lkml/2015/12/10/50
(The mail is attached for your convenience)

> > 2.  With the patch, hv_fcopy_onchannelcallback() can be invoked in the
> > tasklet (i.e., vmbus_on_event(). NB: local irq is enabled), and in the
> > hard irq handler(the IPI handler, e.g.,
> > fcopy_poll_wrapper() -> fcopy_poll_wrapper()).
> >
> > Can the former be interrupted by the latter?
> > e.g., when the callback is running in the tasklet on vCPU0,
> > fcopy_timeout_func() or fcopy_on_msg() could send the IPI to
> > vCPU0 from another vCPU.
> 
> Keep in mind that when the poll function is run, the state will not be
> HVUTIL_READY. The state will be set to HVUTIL_READY in the IPI
> handler. So, it is ok if the tasklet is interrupted by the IPI handler.
> 
> K. Y

Got it.

BTW, in fcopy_handle_handshake(), IMO the line
fcopy_transaction.state = HVUTIL_READY;
just before 
hv_poll_channel(fcopy_transaction.recv_channel, fcopy_poll_wrapper);
should be removed? Because in fcopy_poll_wrapper() we always have
the same line. 

Ditto for kvp/vss.

Thanks,
-- Dexuan
--- Begin Message ---
I found this by chance. I don't have a specific bug caused by this.

Cc: Vitaly Kuznetsov 
Cc: "K. Y. Srinivasan" 
Signed-off-by: Dexuan Cui 
Cc: sta...@vger.kernel.org
---
 tools/hv/hv_vss_daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index 96234b6..5d51d6f 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
syslog(LOG_ERR, "Illegal op:%d\n", op);
}
vss_msg->error = error;
-   len = write(vss_fd, , sizeof(struct hv_vss_msg));
+   len = write(vss_fd, vss_msg, sizeof(struct hv_vss_msg));
if (len != sizeof(struct hv_vss_msg)) {
syslog(LOG_ERR, "write failed; error: %d %s", errno,
   strerror(errno));
--
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fdriverdev.linuxdriverproject.org%2fmailman%2flistinfo%2fdriverdev-devel=01%7c01%7cdecui%40064d.mgd.microsoft.com%7c6038ce2d24784746fa0408d30134f8d9%7c72f988bf86f141af91ab2d7cd011db47%7c1=6Hs1UNlA11wBtnU5XvHhpCgkUlIhWVMKxPHVj9UAZq8%3d
--- End Message ---
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v1 2/3] staging: rtl8188eu: replace open-coded print_hex_dump()

2015-12-10 Thread Andy Shevchenko
No need to reinvent a wheel, i.e. print_hex_dump(). Replace an open-coded
variant by generic kernel helper.

Signed-off-by: Andy Shevchenko 
---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 39 +--
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c 
b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 110b8c0..3f03999 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -1274,32 +1274,25 @@ static int validate_recv_frame(struct adapter *adapter,
/* Dump rx packets */
rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
if (bDumpRxPkt == 1) {/* dump all rx packets */
-   int i;
-   DBG_88E("#\n");
-
-   for (i = 0; i < 64; i += 8)
-   DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", 
*(ptr+i),
-   *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), 
*(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
-   DBG_88E("#\n");
+   if (_drv_err_ <= GlobalDebugLevel) {
+   pr_info(DRIVER_PREFIX 
"#\n");
+   print_hex_dump(KERN_INFO, DRIVER_PREFIX, 
DUMP_PREFIX_NONE,
+   16, 1, ptr, 64, false);
+   pr_info(DRIVER_PREFIX 
"#\n");
+   }
} else if (bDumpRxPkt == 2) {
-   if (type == WIFI_MGT_TYPE) {
-   int i;
-   DBG_88E("#\n");
-
-   for (i = 0; i < 64; i += 8)
-   
DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
-   *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), 
*(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
-   DBG_88E("#\n");
+   if ((_drv_err_ <= GlobalDebugLevel) && (type == WIFI_MGT_TYPE)) 
{
+   pr_info(DRIVER_PREFIX 
"#\n");
+   print_hex_dump(KERN_INFO, DRIVER_PREFIX, 
DUMP_PREFIX_NONE,
+   16, 1, ptr, 64, false);
+   pr_info(DRIVER_PREFIX 
"#\n");
}
} else if (bDumpRxPkt == 3) {
-   if (type == WIFI_DATA_TYPE) {
-   int i;
-   DBG_88E("#\n");
-
-   for (i = 0; i < 64; i += 8)
-   
DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
-   *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), 
*(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
-   DBG_88E("#\n");
+   if ((_drv_err_ <= GlobalDebugLevel) && (type == 
WIFI_DATA_TYPE)) {
+   pr_info(DRIVER_PREFIX 
"#\n");
+   print_hex_dump(KERN_INFO, DRIVER_PREFIX, 
DUMP_PREFIX_NONE,
+   16, 1, ptr, 64, false);
+   pr_info(DRIVER_PREFIX 
"#\n");
}
}
switch (type) {
-- 
2.6.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: goldfish: Coding Style Fix Comparison to NULL could

2015-12-10 Thread Sudip Mukherjee
On Thu, Dec 10, 2015 at 06:31:09PM -0500, Benjamin Young wrote:
> From 4b8ce6b3bd7effdfff2c95fbeb4a20cb93d5e9e5 Mon Sep 17 00:00:00 2001
> From: Benjamin Young 
> Date: Thu, 10 Dec 2015 17:31:00 -0500
> Subject: [PATCH] staging: goldfish: Coding Style Fix - spaces preferred around
>  that '+'

Regarding all the three patches: The above header information should not
be here.

Regarding this patch: This is a repeat of the previous patch with the
subject of the next patch.

regards
sudip
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Style Fix: Blank lines after declaration

2015-12-10 Thread Sudip Mukherjee
On Thu, Dec 10, 2015 at 06:00:14AM -0700, BryanSPaul wrote:
> WARNING: Missing a blank line after declarations lines added
> 
> Signed-off-by: Bryan Paul 
> ---
Your name in the From: header and Signedoff-by name should match.

>  drivers/staging/rtl8188eu/core/rtw_efuse.c | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c 
> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index eb89423..5f71088 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> @@ -220,6 +220,7 @@ static void efuse_read_phymap_from_txpktbuf(
>   struct adapter  *adapter,
>   int bcnhead,/* beacon head, where FW store len(2-byte) and efuse 
> physical map. */
>   u8 *content,/* buffer to store efuse physical map */
> +
>   u16 *size   /* for efuse content: the max byte to read. will update 
> to byte read */

Why you will need a blank line here? These are part of function
arguments.

regards
sudip
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging:rtl8192u: fixes the following sparse warning:

2015-12-10 Thread Jandy Gou
drivers/staging/rtl8192u/r8192U_core.c:3212:6: warning: symbol
'rtl819x_watchdog_wqcallback' was not declared. Should it be static?
drivers/staging/rtl8192u/r8192U_core.c:3276:6: warning: symbol
'watch_dog_timer_callback' was not declared. Should it be static?
drivers/staging/rtl8192u/r8192U_core.c:3282:5: warning: symbol
'_rtl8192_up' was not declared. Should it be static?
drivers/staging/rtl8192u/r8192U_core.c::5: warning: symbol
'rtl8192_close' was not declared. Should it be static?
drivers/staging/rtl8192u/r8192U_core.c:3406:6: warning: symbol
'rtl8192_restart' was not declared. Should it be static?
drivers/staging/rtl8192u/r8192U_core.c:4618:6: warning: symbol
'rtl8192_irq_rx_tasklet' was not declared. Should it be static?
drivers/staging/rtl8192u/r8192U_core.c:4736:6: warning: symbol
'rtl8192_cancel_deferred_work' was not declared. Should it be static?

Signed-off-by: Jandy Gou 
---
 drivers/staging/rtl8192u/r8192U_core.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index a4795af..1343322 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -3209,7 +3209,7 @@ static void rtl819x_update_rxcounts(struct r8192_priv 
*priv, u32 *TotalRxBcnNum,
 }
 
 
-void rtl819x_watchdog_wqcallback(struct work_struct *work)
+static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 {
struct delayed_work *dwork = container_of(work, struct delayed_work, 
work);
struct r8192_priv *priv = container_of(dwork, struct r8192_priv, 
watch_dog_wq);
@@ -3273,13 +3273,13 @@ void rtl819x_watchdog_wqcallback(struct work_struct 
*work)
 
 }
 
-void watch_dog_timer_callback(unsigned long data)
+static void watch_dog_timer_callback(unsigned long data)
 {
struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
queue_delayed_work(priv->priv_wq, >watch_dog_wq, 0);
mod_timer(>watch_dog_timer, jiffies + 
MSECS(IEEE80211_WATCH_DOG_TIME));
 }
-int _rtl8192_up(struct net_device *dev)
+static int _rtl8192_up(struct net_device *dev)
 {
struct r8192_priv *priv = ieee80211_priv(dev);
int init_status = 0;
@@ -3330,7 +3330,7 @@ int rtl8192_up(struct net_device *dev)
 }
 
 
-int rtl8192_close(struct net_device *dev)
+static int rtl8192_close(struct net_device *dev)
 {
struct r8192_priv *priv = ieee80211_priv(dev);
int ret;
@@ -3403,7 +3403,7 @@ void rtl8192_commit(struct net_device *dev)
 
 }
 
-void rtl8192_restart(struct work_struct *work)
+static void rtl8192_restart(struct work_struct *work)
 {
struct r8192_priv *priv = container_of(work, struct r8192_priv, 
reset_wq);
struct net_device *dev = priv->ieee80211->dev;
@@ -4615,7 +4615,7 @@ static void rtl8192_rx_cmd(struct sk_buff *skb)
}
 }
 
-void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
+static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
 {
struct sk_buff *skb;
struct rtl8192_rx_info *info;
@@ -4733,7 +4733,7 @@ fail:
 }
 
 //detach all the work and timer structure declared or inititialize in 
r8192U_init function.
-void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
+static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
 {
 
cancel_work_sync(>reset_wq);
-- 
1.9.1


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging/rdma/hfi1: add definitions for OPA traps

2015-12-10 Thread Mike Marciniszyn
From: Jubin John 

These new definitions will be used by follow-on
patches for formating and sending OPA traps.

Reviewed-by: Ira Weiny 
Signed-off-by: Jubin John 
---
 drivers/staging/rdma/hfi1/mad.h |  114 +++
 1 file changed, 114 insertions(+)

diff --git a/drivers/staging/rdma/hfi1/mad.h b/drivers/staging/rdma/hfi1/mad.h
index 4745750..f031775 100644
--- a/drivers/staging/rdma/hfi1/mad.h
+++ b/drivers/staging/rdma/hfi1/mad.h
@@ -60,7 +60,121 @@
 #endif
 #include "opa_compat.h"
 
+/*
+ * OPA Traps
+ */
+#define OPA_TRAP_GID_NOW_IN_SERVICE cpu_to_be16(64)
+#define OPA_TRAP_GID_OUT_OF_SERVICE cpu_to_be16(65)
+#define OPA_TRAP_ADD_MULTICAST_GROUPcpu_to_be16(66)
+#define OPA_TRAL_DEL_MULTICAST_GROUPcpu_to_be16(67)
+#define OPA_TRAP_UNPATH cpu_to_be16(68)
+#define OPA_TRAP_REPATH cpu_to_be16(69)
+#define OPA_TRAP_PORT_CHANGE_STATE  cpu_to_be16(128)
+#define OPA_TRAP_LINK_INTEGRITY cpu_to_be16(129)
+#define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN   cpu_to_be16(130)
+#define OPA_TRAP_FLOW_WATCHDOG  cpu_to_be16(131)
+#define OPA_TRAP_CHANGE_CAPABILITY  cpu_to_be16(144)
+#define OPA_TRAP_CHANGE_SYSGUID cpu_to_be16(145)
+#define OPA_TRAP_BAD_M_KEY  cpu_to_be16(256)
+#define OPA_TRAP_BAD_P_KEY  cpu_to_be16(257)
+#define OPA_TRAP_BAD_Q_KEY  cpu_to_be16(258)
+#define OPA_TRAP_SWITCH_BAD_PKEYcpu_to_be16(259)
+#define OPA_SMA_TRAP_DATA_LINK_WIDTHcpu_to_be16(2048)
 
+/*
+ * Generic trap/notice other local changes flags (trap 144).
+ */
+#defineOPA_NOTICE_TRAP_LWDE_CHG0x08 /* Link Width Downgrade 
Enable
+ * changed
+ */
+#define OPA_NOTICE_TRAP_LSE_CHG 0x04 /* Link Speed Enable changed */
+#define OPA_NOTICE_TRAP_LWE_CHG 0x02 /* Link Width Enable changed */
+#define OPA_NOTICE_TRAP_NODE_DESC_CHG   0x01
+
+struct opa_mad_notice_attr {
+   u8 generic_type;
+   u8 prod_type_msb;
+   __be16 prod_type_lsb;
+   __be16 trap_num;
+   __be16 toggle_count;
+   __be32 issuer_lid;
+   __be32 reserved1;
+   union ib_gid issuer_gid;
+
+   union {
+   struct {
+   u8  details[64];
+   } raw_data;
+
+   struct {
+   union ib_gidgid;
+   } __packed ntc_64_65_66_67;
+
+   struct {
+   __be32  lid;
+   } __packed ntc_128;
+
+   struct {
+   __be32  lid;/* where violation happened */
+   u8  port_num;   /* where violation happened */
+   } __packed ntc_129_130_131;
+
+   struct {
+   __be32  lid;/* LID where change occurred */
+   __be32  new_cap_mask;   /* new capability mask */
+   __be16  reserved2;
+   __be16  cap_mask;
+   __be16  change_flags;   /* low 4 bits only */
+   } __packed ntc_144;
+
+   struct {
+   __be64  new_sys_guid;
+   __be32  lid;/* lid where sys guid changed */
+   } __packed ntc_145;
+
+   struct {
+   __be32  lid;
+   __be32  dr_slid;
+   u8  method;
+   u8  dr_trunc_hop;
+   __be16  attr_id;
+   __be32  attr_mod;
+   __be64  mkey;
+   u8  dr_rtn_path[30];
+   } __packed ntc_256;
+
+   struct {
+   __be32  lid1;
+   __be32  lid2;
+   __be32  key;
+   u8  sl; /* SL: high 5 bits */
+   u8  reserved3[3];
+   union ib_gidgid1;
+   union ib_gidgid2;
+   __be32  qp1;/* high 8 bits reserved */
+   __be32  qp2;/* high 8 bits reserved */
+   } __packed ntc_257_258;
+
+   struct {
+   __be16  flags;  /* low 8 bits reserved */
+   __be16  pkey;
+   __be32  lid1;
+   __be32  lid2;
+   u8  sl; /* SL: high 5 bits */
+   u8  reserved4[3];
+   union ib_gidgid1;
+   union ib_gidgid2;
+  

[PATCH 2/2] staging: COMEDI: Added missing spaces at binary operators

2015-12-10 Thread Moritz König
This patch adds missing spaces at binary operators in comedi.h.

Signed-off-by: Moritz König 
Signed-off-by: Fabian Lang 
---
 drivers/staging/comedi/comedi.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index 626c4fe..61cd152 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -63,21 +63,21 @@
 /* packs and unpacks a channel/range number */
 
 #define CR_PACK(chan, rng, aref)   \
-   aref)&0x3)<<24) | (((rng)&0xff)<<16) | (chan))
+   aref)&0x3) << 24) | (((rng)&0xff) << 16) | (chan))
 #define CR_PACK_FLAGS(chan, range, aref, flags)
\
(CR_PACK(chan, range, aref) | ((flags) & CR_FLAGS_MASK))
 
 #define CR_CHAN(a) ((a)&0x)
-#define CR_RANGE(a)(((a)>>16)&0xff)
-#define CR_AREF(a) (((a)>>24)&0x03)
+#define CR_RANGE(a)(((a) >> 16)&0xff)
+#define CR_AREF(a) (((a) >> 24)&0x03)
 
 #define CR_FLAGS_MASK  0xfc00
-#define CR_ALT_FILTER  (1<<26)
+#define CR_ALT_FILTER  (1 << 26)
 #define CR_DITHER  CR_ALT_FILTER
 #define CR_DEGLITCHCR_ALT_FILTER
-#define CR_ALT_SOURCE  (1<<27)
-#define CR_EDGE(1<<30)
-#define CR_INVERT  (1<<31)
+#define CR_ALT_SOURCE  (1 << 27)
+#define CR_EDGE(1 << 30)
+#define CR_INVERT  (1 << 31)
 
 #define AREF_GROUND0x00/* analog ref = analog ground */
 #define AREF_COMMON0x01/* analog ref = analog common */
@@ -114,11 +114,11 @@
 
 #define INSN_READ  (0 | INSN_MASK_READ)
 #define INSN_WRITE (1 | INSN_MASK_WRITE)
-#define INSN_BITS  (2 | INSN_MASK_READ|INSN_MASK_WRITE)
-#define INSN_CONFIG(3 | INSN_MASK_READ|INSN_MASK_WRITE)
-#define INSN_GTOD  (4 | INSN_MASK_READ|INSN_MASK_SPECIAL)
-#define INSN_WAIT  (5 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
-#define INSN_INTTRIG   (6 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
+#define INSN_BITS  (2 | INSN_MASK_READ | INSN_MASK_WRITE)
+#define INSN_CONFIG(3 | INSN_MASK_READ | INSN_MASK_WRITE)
+#define INSN_GTOD  (4 | INSN_MASK_READ | INSN_MASK_SPECIAL)
+#define INSN_WAIT  (5 | INSN_MASK_WRITE | INSN_MASK_SPECIAL)
+#define INSN_INTTRIG   (6 | INSN_MASK_WRITE | INSN_MASK_SPECIAL)
 
 /* trigger flags */
 /* These flags are used in comedi_trig structures */
@@ -504,13 +504,13 @@ struct comedi_bufinfo {
 
 /* range stuff */
 
-#define __RANGE(a, b)  a)&0x)<<16)|((b)&0x))
+#define __RANGE(a, b)  a)&0x) << 16) | ((b)&0x))
 
-#define RANGE_OFFSET(a)(((a)>>16)&0x)
+#define RANGE_OFFSET(a)(((a) >> 16)&0x)
 #define RANGE_LENGTH(b)((b)&0x)
 
 #define RF_UNIT(flags) ((flags)&0xff)
-#define RF_EXTERNAL(1<<8)
+#define RF_EXTERNAL(1 << 8)
 
 #define UNIT_volt  0
 #define UNIT_mA1
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: COMEDI: Fixed the format of comments

2015-12-10 Thread Moritz König
This patch fixes the format of comments in comedi.h.

Signed-off-by: Moritz König 
Signed-off-by: Fabian Lang 
---
 drivers/staging/comedi/comedi.h | 202 +++-
 1 file changed, 116 insertions(+), 86 deletions(-)

diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index 66edda1..626c4fe 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -1,20 +1,20 @@
 /*
-include/comedi.h (installed as /usr/include/comedi.h)
-header file for comedi
-
-COMEDI - Linux Control and Measurement Device Interface
-Copyright (C) 1998-2001 David A. Schleef 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that 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.
-*/
+ *  include/comedi.h (installed as /usr/include/comedi.h)
+ *  header file for comedi
+ *
+ *  COMEDI - Linux Control and Measurement Device Interface
+ *  Copyright (C) 1998-2001 David A. Schleef 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that 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.
+ */
 
 #ifndef _COMEDI_H
 #define _COMEDI_H
@@ -28,9 +28,9 @@
 #define COMEDI_MAJOR 98
 
 /*
-   maximum number of minor devices.  This can be increased, although
-   kernel structures are currently statically allocated, thus you
-   don't want this to be much more than you actually use.
+ * maximum number of minor devices.  This can be increased, although
+ * kernel structures are currently statically allocated, thus you
+ * don't want this to be much more than you actually use.
  */
 #define COMEDI_NDEVICES 16
 
@@ -46,7 +46,7 @@
  * now used by all comedi drivers instead.
  */
 
-/* length of nth chunk of firmware data -*/
+/* length of nth chunk of firmware data */
 #define COMEDI_DEVCONF_AUX_DATA3_LENGTH25
 #define COMEDI_DEVCONF_AUX_DATA2_LENGTH26
 #define COMEDI_DEVCONF_AUX_DATA1_LENGTH27
@@ -279,7 +279,8 @@ enum configuration_ids {
INSN_CONFIG_SET_OTHER_SRC = 2005, /* Set other source */
/* INSN_CONFIG_GET_OTHER_SRC = 2006,*//* Get other source */
/* Get size in bytes of subdevice's on-board fifos used during
-* streaming input/output */
+* streaming input/output
+*/
INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE = 2006,
INSN_CONFIG_SET_COUNTER_MODE = 4097,
/* INSN_CONFIG_8254_SET_MODE is deprecated */
@@ -292,7 +293,8 @@ enum configuration_ids {
INSN_CONFIG_PWM_GET_PERIOD = 5001,  /* gets frequency */
INSN_CONFIG_GET_PWM_STATUS = 5002,  /* is it running? */
/* sets H bridge: duty cycle and sign bit for a relay at the
-* same time */
+* same time
+*/
INSN_CONFIG_PWM_SET_H_BRIDGE = 5003,
/* gets H bridge data: duty cycle and the sign bit */
INSN_CONFIG_PWM_GET_H_BRIDGE = 5004
@@ -521,23 +523,22 @@ struct comedi_bufinfo {
 /**/
 
 /*
-  8254 specific configuration.
-
-  It supports two config commands:
-
-  0 ID: INSN_CONFIG_SET_COUNTER_MODE
-  1 8254 Mode
-I8254_MODE0, I8254_MODE1, ..., I8254_MODE5
-OR'ed with:
-I8254_BCD, I8254_BINARY
-
-  0 ID: INSN_CONFIG_8254_READ_STATUS
-  1 <-- Status byte returned here.
-B7 = Output
-B6 = NULL Count
-B5 - B0 Current mode.
-
-*/
+ * 8254 specific configuration.
+ *
+ * It supports two config commands:
+ *
+ * 0 ID: INSN_CONFIG_SET_COUNTER_MODE
+ * 1 8254 Mode
+ *   I8254_MODE0, I8254_MODE1, ..., I8254_MODE5
+ *   OR'ed with:
+ *   I8254_BCD, I8254_BINARY
+ *
+ * 0 ID: INSN_CONFIG_8254_READ_STATUS
+ * 1 <-- Status byte returned here.
+ *   B7 = Output
+ *   B6 = NULL Count
+ *   B5 - B0 Current mode.
+ */
 
 enum i8254_mode {
I8254_MODE0 = (0 << 1), /* Interrupt on terminal count */
@@ -546,9 +547,11 @@ enum i8254_mode {
I8254_MODE3 = (3 << 1), /* Square wave mode */
I8254_MODE4 = (4 << 1), /* Software triggered strobe */
I8254_MODE5 = (5 << 1), /* Hardware triggered strobe
-* 

[PATCH 2/2] staging/rdma/hfi1: HFI now sends OPA Traps instead of IBTA

2015-12-10 Thread Mike Marciniszyn
From: Erik E. Kahn 

send_trap() was still using old ib_smp instead of opa_smp
for formatting and sending traps.

Reviewed-by: Arthur Kepner 
Reviewed-by: Ira Weiny 
Reviewed-by: Dennis Dalessandro 
Signed-off-by: Jubin John 
Signed-off-by: Erik E. Kahn 
---
 drivers/staging/rdma/hfi1/mad.c   |  121 +++--
 drivers/staging/rdma/hfi1/ruc.c   |   10 ++-
 drivers/staging/rdma/hfi1/ud.c|   21 +++---
 drivers/staging/rdma/hfi1/verbs.h |2 -
 4 files changed, 79 insertions(+), 75 deletions(-)

diff --git a/drivers/staging/rdma/hfi1/mad.c b/drivers/staging/rdma/hfi1/mad.c
index a122565..28c3ad2 100644
--- a/drivers/staging/rdma/hfi1/mad.c
+++ b/drivers/staging/rdma/hfi1/mad.c
@@ -84,7 +84,7 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, 
unsigned len)
 {
struct ib_mad_send_buf *send_buf;
struct ib_mad_agent *agent;
-   struct ib_smp *smp;
+   struct opa_smp *smp;
int ret;
unsigned long flags;
unsigned long timeout;
@@ -117,15 +117,15 @@ static void send_trap(struct hfi1_ibport *ibp, void 
*data, unsigned len)
return;
 
smp = send_buf->mad;
-   smp->base_version = IB_MGMT_BASE_VERSION;
+   smp->base_version = OPA_MGMT_BASE_VERSION;
smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
-   smp->class_version = 1;
+   smp->class_version = OPA_SMI_CLASS_VERSION;
smp->method = IB_MGMT_METHOD_TRAP;
ibp->tid++;
smp->tid = cpu_to_be64(ibp->tid);
smp->attr_id = IB_SMP_ATTR_NOTICE;
/* o14-1: smp->mkey = 0; */
-   memcpy(smp->data, data, len);
+   memcpy(smp->route.lid.data, data, len);
 
spin_lock_irqsave(>lock, flags);
if (!ibp->sm_ah) {
@@ -164,11 +164,16 @@ static void send_trap(struct hfi1_ibport *ibp, void 
*data, unsigned len)
  * Send a bad [PQ]_Key trap (ch. 14.3.8).
  */
 void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
-   u32 qp1, u32 qp2, __be16 lid1, __be16 lid2)
+   u32 qp1, u32 qp2, u16 lid1, u16 lid2)
 {
-   struct ib_mad_notice_attr data;
+   struct opa_mad_notice_attr data;
+   u32 lid = ppd_from_ibp(ibp)->lid;
+   u32 _lid1 = lid1;
+   u32 _lid2 = lid2;
 
-   if (trap_num == IB_NOTICE_TRAP_BAD_PKEY)
+   memset(, 0, sizeof(data));
+
+   if (trap_num == OPA_TRAP_BAD_P_KEY)
ibp->pkey_violations++;
else
ibp->qkey_violations++;
@@ -176,17 +181,15 @@ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 
trap_num, u32 key, u32 sl,
 
/* Send violation trap */
data.generic_type = IB_NOTICE_TYPE_SECURITY;
-   data.prod_type_msb = 0;
data.prod_type_lsb = IB_NOTICE_PROD_CA;
data.trap_num = trap_num;
-   data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
-   data.toggle_count = 0;
-   memset(, 0, sizeof(data.details));
-   data.details.ntc_257_258.lid1 = lid1;
-   data.details.ntc_257_258.lid2 = lid2;
-   data.details.ntc_257_258.key = cpu_to_be32(key);
-   data.details.ntc_257_258.sl_qp1 = cpu_to_be32((sl << 28) | qp1);
-   data.details.ntc_257_258.qp2 = cpu_to_be32(qp2);
+   data.issuer_lid = cpu_to_be32(lid);
+   data.ntc_257_258.lid1 = cpu_to_be32(_lid1);
+   data.ntc_257_258.lid2 = cpu_to_be32(_lid2);
+   data.ntc_257_258.key = cpu_to_be32(key);
+   data.ntc_257_258.sl = sl << 3;
+   data.ntc_257_258.qp1 = cpu_to_be32(qp1);
+   data.ntc_257_258.qp2 = cpu_to_be32(qp2);
 
send_trap(ibp, , sizeof(data));
 }
@@ -197,32 +200,30 @@ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 
trap_num, u32 key, u32 sl,
 static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad,
 __be64 mkey, __be32 dr_slid, u8 return_path[], u8 hop_cnt)
 {
-   struct ib_mad_notice_attr data;
+   struct opa_mad_notice_attr data;
+   u32 lid = ppd_from_ibp(ibp)->lid;
 
+   memset(, 0, sizeof(data));
/* Send violation trap */
data.generic_type = IB_NOTICE_TYPE_SECURITY;
-   data.prod_type_msb = 0;
data.prod_type_lsb = IB_NOTICE_PROD_CA;
-   data.trap_num = IB_NOTICE_TRAP_BAD_MKEY;
-   data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
-   data.toggle_count = 0;
-   memset(, 0, sizeof(data.details));
-   data.details.ntc_256.lid = data.issuer_lid;
-   data.details.ntc_256.method = mad->method;
-   data.details.ntc_256.attr_id = mad->attr_id;
-   data.details.ntc_256.attr_mod = mad->attr_mod;
-   data.details.ntc_256.mkey = mkey;
+   data.trap_num = OPA_TRAP_BAD_M_KEY;
+   data.issuer_lid = cpu_to_be32(lid);
+   data.ntc_256.lid = data.issuer_lid;
+   data.ntc_256.method = mad->method;
+   data.ntc_256.attr_id = mad->attr_id;
+   

[PATCH 0/2] staging: COMEDI: checkpatch.pl cleanups in comedi.h

2015-12-10 Thread Moritz König
This patchset fixes all the warnings and legitimate checks of
checkpatch.pl in comedi.h. 

The following warnings were fixed:
 * WARNING: Block comments use * on subsequent lines
 * WARNING: Block comments use a trailing */ on a separate line
The following checks were fixed:
 * CHECK: spaces preferred around that '<<' (ctx:VxV)
 * CHECK: spaces preferred around that '>>' (ctx:VxV)
 * CHECK: spaces preferred around that '|' (ctx:VxV)

The following checks are not legitimate here and were not fixed:
 * CHECK: spaces preferred around that '&' (ctx:VxV)
This '&' is not a binary operator, but a referencing.
 * CHECK: Prefer using the BIT macro
The author defined a BIT macro here.
 * CHECK: Avoid CamelCase: 
This refers to the unit 'milli ampere'.

Moritz König (2):
  staging: COMEDI: Fixed the format of comments
  staging: COMEDI: Added missing spaces at binary operators

 drivers/staging/comedi/comedi.h | 232 +++-
 1 file changed, 131 insertions(+), 101 deletions(-)

-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] staging: gdm72xx: add userspace data struct

2015-12-10 Thread One Thousand Gnomes
>   if (cmd != SIOCWMIOCTL)
>   return -EOPNOTSUPP;
> @@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, 
> struct ifreq *ifr, int cmd)
>   /* NOTE: gdm_update_fsm should be called
>* before gdm_wimax_ioctl_set_data is called.
>*/
> - gdm_update_fsm(dev,
> -req->data.buf);
> + fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
> + if (!fsm_buf)
> + return -ENOMEM;
> + if (copy_from_user(fsm_buf, req->data.buf,
> +sizeof(fsm_s))) {
> + kfree(fsm_buf);
> + return -EFAULT;
> + }
> + gdm_update_fsm(dev, fsm_buf);
> + kfree(fsm_buf);

fsm_s is a total of 12 bytes so this is complete overkill. If you are
copying a large object then yes the pattern you have used is correct
(except that you mean sizeof(struct fsm_s) and it doesn't compile at the
moment!

data_s can just be modified to be __user. All uses of it follow that
rule.

All I think you need in this case is

struct fsm_s fsm_buf;

if (copy_from_user(_buf, req->data.buf,sizeof(buf))
return -EFAULT
gdm_update_fsm(_buf);

If you are touching the structs it might be wise to fix the other
problems with them notably the use of int. sizes when used are unsigned -
and signed sizes are asking for errors. In fact if you look at the
existing uses of the size checks they look deeply suspicious the moment
anything malicious passes in negative numbers.



All the types in the ioctl structures also ought to be proper fixed sizes
but that's another matter.

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v1 1/3] staging: rtl8188eu: provide an absolute path to include folder

2015-12-10 Thread Andy Shevchenko
Otherwise compiler will complain as follows

  CC [M]  drivers/staging/rtl8188eu/core/rtw_ap.o
cc1: warning: drivers/staging/rtl8188eu/include: No such file or directory 
[-Wmissing-include-dirs]

Signed-off-by: Andy Shevchenko 
---
 drivers/staging/rtl8188eu/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/Makefile 
b/drivers/staging/rtl8188eu/Makefile
index ed72358..29b9834 100644
--- a/drivers/staging/rtl8188eu/Makefile
+++ b/drivers/staging/rtl8188eu/Makefile
@@ -53,4 +53,4 @@ r8188eu-y :=  \
 
 obj-$(CONFIG_R8188EU)  := r8188eu.o
 
-ccflags-y += -D__CHECK_ENDIAN__ -I$(src)/include
+ccflags-y += -D__CHECK_ENDIAN__ -I$(srctree)/$(src)/include
-- 
2.6.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging/rdma/hfi1: Fix a possible null pointer dereference

2015-12-10 Thread Mike Marciniszyn
From: Easwar Hariharan 

A code inspection pointed out that kmalloc_array may return NULL and
memset doesn't check the input pointer for NULL, resulting in a possible
NULL dereference. This patch fixes this.

Reviewed-by: Mike Marciniszyn 
Signed-off-by: Easwar Hariharan 
---
 drivers/staging/rdma/hfi1/chip.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/rdma/hfi1/chip.c b/drivers/staging/rdma/hfi1/chip.c
index dc69159..49d49b2 100644
--- a/drivers/staging/rdma/hfi1/chip.c
+++ b/drivers/staging/rdma/hfi1/chip.c
@@ -10129,6 +10129,8 @@ static void init_qos(struct hfi1_devdata *dd, u32 
first_ctxt)
if (num_vls * qpns_per_vl > dd->chip_rcv_contexts)
goto bail;
rsmmap = kmalloc_array(NUM_MAP_REGS, sizeof(u64), GFP_KERNEL);
+   if (!rsmmap)
+   goto bail;
memset(rsmmap, rxcontext, NUM_MAP_REGS * sizeof(u64));
/* init the local copy of the table */
for (i = 0, ctxt = first_ctxt; i < num_vls; i++) {

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


  1   2   >