Skip to content

Commit

Permalink
treewide: Constify most dma_map_ops structures
Browse files Browse the repository at this point in the history
Most dma_map_ops structures are never modified. Constify these
structures such that these can be write-protected. This patch
has been generated as follows:

git grep -l 'struct dma_map_ops' |
  xargs -d\\n sed -i \
    -e 's/struct dma_map_ops/const struct dma_map_ops/g' \
    -e 's/const struct dma_map_ops {/struct dma_map_ops {/g' \
    -e 's/^const struct dma_map_ops;$/struct dma_map_ops;/' \
    -e 's/const const struct dma_map_ops /const struct dma_map_ops /g';
sed -i -e 's/const \(struct dma_map_ops intel_dma_ops\)/\1/' \
  $(git grep -l 'struct dma_map_ops intel_dma_ops');
sed -i -e 's/const \(struct dma_map_ops dma_iommu_ops\)/\1/' \
  $(git grep -l 'struct dma_map_ops' | grep ^arch/powerpc);
sed -i -e '/^struct vmd_dev {$/,/^};$/ s/const \(struct dma_map_ops[[:blank:]]dma_ops;\)/\1/' \
       -e '/^static void vmd_setup_dma_ops/,/^}$/ s/const \(struct dma_map_ops \*dest\)/\1/' \
       -e 's/const \(struct dma_map_ops \*dest = \&vmd->dma_ops\)/\1/' \
    drivers/pci/host/*.c
sed -i -e '/^void __init pci_iommu_alloc(void)$/,/^}$/ s/dma_ops->/intel_dma_ops./' arch/ia64/kernel/pci-dma.c
sed -i -e 's/static const struct dma_map_ops sn_dma_ops/static struct dma_map_ops sn_dma_ops/' arch/ia64/sn/pci/pci_dma.c
sed -i -e 's/(const struct dma_map_ops \*)//' drivers/misc/mic/bus/vop_bus.c

Signed-off-by: Bart Van Assche <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Russell King <[email protected]>
Cc: [email protected]
Signed-off-by: Doug Ledford <[email protected]>
  • Loading branch information
Bart Van Assche authored and dledford committed Jan 24, 2017
1 parent 102c5ce commit 5299709
Show file tree
Hide file tree
Showing 113 changed files with 227 additions and 227 deletions.
4 changes: 2 additions & 2 deletions arch/alpha/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _ALPHA_DMA_MAPPING_H
#define _ALPHA_DMA_MAPPING_H

extern struct dma_map_ops *dma_ops;
extern const struct dma_map_ops *dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return dma_ops;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/alpha/kernel/pci-noop.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static int alpha_noop_supported(struct device *dev, u64 mask)
return mask < 0x00ffffffUL ? 0 : 1;
}

struct dma_map_ops alpha_noop_ops = {
const struct dma_map_ops alpha_noop_ops = {
.alloc = alpha_noop_alloc_coherent,
.free = dma_noop_free_coherent,
.map_page = dma_noop_map_page,
Expand All @@ -137,5 +137,5 @@ struct dma_map_ops alpha_noop_ops = {
.dma_supported = alpha_noop_supported,
};

struct dma_map_ops *dma_ops = &alpha_noop_ops;
const struct dma_map_ops *dma_ops = &alpha_noop_ops;
EXPORT_SYMBOL(dma_ops);
4 changes: 2 additions & 2 deletions arch/alpha/kernel/pci_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ static int alpha_pci_mapping_error(struct device *dev, dma_addr_t dma_addr)
return dma_addr == 0;
}

struct dma_map_ops alpha_pci_ops = {
const struct dma_map_ops alpha_pci_ops = {
.alloc = alpha_pci_alloc_coherent,
.free = alpha_pci_free_coherent,
.map_page = alpha_pci_map_page,
Expand All @@ -950,5 +950,5 @@ struct dma_map_ops alpha_pci_ops = {
.dma_supported = alpha_pci_supported,
};

struct dma_map_ops *dma_ops = &alpha_pci_ops;
const struct dma_map_ops *dma_ops = &alpha_pci_ops;
EXPORT_SYMBOL(dma_ops);
4 changes: 2 additions & 2 deletions arch/arc/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <plat/dma.h>
#endif

extern struct dma_map_ops arc_dma_ops;
extern const struct dma_map_ops arc_dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return &arc_dma_ops;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/mm/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static int arc_dma_supported(struct device *dev, u64 dma_mask)
return dma_mask == DMA_BIT_MASK(32);
}

struct dma_map_ops arc_dma_ops = {
const struct dma_map_ops arc_dma_ops = {
.alloc = arc_dma_alloc,
.free = arc_dma_free,
.mmap = arc_dma_mmap,
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/common/dmabounce.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static int dmabounce_set_mask(struct device *dev, u64 dma_mask)
return arm_dma_ops.set_dma_mask(dev, dma_mask);
}

static struct dma_map_ops dmabounce_ops = {
static const struct dma_map_ops dmabounce_ops = {
.alloc = arm_dma_alloc,
.free = arm_dma_free,
.mmap = arm_dma_mmap,
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/include/asm/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define ASMARM_DEVICE_H

struct dev_archdata {
struct dma_map_ops *dma_ops;
const struct dma_map_ops *dma_ops;
#ifdef CONFIG_DMABOUNCE
struct dmabounce_device_info *dmabounce;
#endif
Expand Down
10 changes: 5 additions & 5 deletions arch/arm/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
#include <asm/xen/hypervisor.h>

#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
extern struct dma_map_ops arm_dma_ops;
extern struct dma_map_ops arm_coherent_dma_ops;
extern const struct dma_map_ops arm_dma_ops;
extern const struct dma_map_ops arm_coherent_dma_ops;

static inline struct dma_map_ops *__generic_dma_ops(struct device *dev)
static inline const struct dma_map_ops *__generic_dma_ops(struct device *dev)
{
if (dev && dev->archdata.dma_ops)
return dev->archdata.dma_ops;
return &arm_dma_ops;
}

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
if (xen_initial_domain())
return xen_dma_ops;
else
return __generic_dma_ops(dev);
}

static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
{
BUG_ON(!dev);
dev->archdata.dma_ops = ops;
Expand Down
22 changes: 11 additions & 11 deletions arch/arm/mm/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static void arm_dma_sync_single_for_device(struct device *dev,
__dma_page_cpu_to_dev(page, offset, size, dir);
}

struct dma_map_ops arm_dma_ops = {
const struct dma_map_ops arm_dma_ops = {
.alloc = arm_dma_alloc,
.free = arm_dma_free,
.mmap = arm_dma_mmap,
Expand All @@ -204,7 +204,7 @@ static int arm_coherent_dma_mmap(struct device *dev, struct vm_area_struct *vma,
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs);

struct dma_map_ops arm_coherent_dma_ops = {
const struct dma_map_ops arm_coherent_dma_ops = {
.alloc = arm_coherent_dma_alloc,
.free = arm_coherent_dma_free,
.mmap = arm_coherent_dma_mmap,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off,
int arm_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
enum dma_data_direction dir, unsigned long attrs)
{
struct dma_map_ops *ops = get_dma_ops(dev);
const struct dma_map_ops *ops = get_dma_ops(dev);
struct scatterlist *s;
int i, j;

Expand Down Expand Up @@ -1101,7 +1101,7 @@ int arm_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
void arm_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
enum dma_data_direction dir, unsigned long attrs)
{
struct dma_map_ops *ops = get_dma_ops(dev);
const struct dma_map_ops *ops = get_dma_ops(dev);
struct scatterlist *s;

int i;
Expand All @@ -1120,7 +1120,7 @@ void arm_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
void arm_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
int nents, enum dma_data_direction dir)
{
struct dma_map_ops *ops = get_dma_ops(dev);
const struct dma_map_ops *ops = get_dma_ops(dev);
struct scatterlist *s;
int i;

Expand All @@ -1139,7 +1139,7 @@ void arm_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
void arm_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
int nents, enum dma_data_direction dir)
{
struct dma_map_ops *ops = get_dma_ops(dev);
const struct dma_map_ops *ops = get_dma_ops(dev);
struct scatterlist *s;
int i;

Expand Down Expand Up @@ -2099,7 +2099,7 @@ static void arm_iommu_sync_single_for_device(struct device *dev,
__dma_page_cpu_to_dev(page, offset, size, dir);
}

struct dma_map_ops iommu_ops = {
const struct dma_map_ops iommu_ops = {
.alloc = arm_iommu_alloc_attrs,
.free = arm_iommu_free_attrs,
.mmap = arm_iommu_mmap_attrs,
Expand All @@ -2119,7 +2119,7 @@ struct dma_map_ops iommu_ops = {
.unmap_resource = arm_iommu_unmap_resource,
};

struct dma_map_ops iommu_coherent_ops = {
const struct dma_map_ops iommu_coherent_ops = {
.alloc = arm_coherent_iommu_alloc_attrs,
.free = arm_coherent_iommu_free_attrs,
.mmap = arm_coherent_iommu_mmap_attrs,
Expand Down Expand Up @@ -2319,7 +2319,7 @@ void arm_iommu_detach_device(struct device *dev)
}
EXPORT_SYMBOL_GPL(arm_iommu_detach_device);

static struct dma_map_ops *arm_get_iommu_dma_map_ops(bool coherent)
static const struct dma_map_ops *arm_get_iommu_dma_map_ops(bool coherent)
{
return coherent ? &iommu_coherent_ops : &iommu_ops;
}
Expand Down Expand Up @@ -2374,15 +2374,15 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) { }

#endif /* CONFIG_ARM_DMA_USE_IOMMU */

static struct dma_map_ops *arm_get_dma_map_ops(bool coherent)
static const struct dma_map_ops *arm_get_dma_map_ops(bool coherent)
{
return coherent ? &arm_coherent_dma_ops : &arm_dma_ops;
}

void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
const struct iommu_ops *iommu, bool coherent)
{
struct dma_map_ops *dma_ops;
const struct dma_map_ops *dma_ops;

dev->archdata.dma_coherent = coherent;
if (arm_setup_iommu_dma_ops(dev, dma_base, size, iommu))
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/xen/mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
}
EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region);

struct dma_map_ops *xen_dma_ops;
const struct dma_map_ops *xen_dma_ops;
EXPORT_SYMBOL(xen_dma_ops);

static struct dma_map_ops xen_swiotlb_dma_ops = {
static const struct dma_map_ops xen_swiotlb_dma_ops = {
.alloc = xen_swiotlb_alloc_coherent,
.free = xen_swiotlb_free_coherent,
.sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/include/asm/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define __ASM_DEVICE_H

struct dev_archdata {
struct dma_map_ops *dma_ops;
const struct dma_map_ops *dma_ops;
#ifdef CONFIG_IOMMU_API
void *iommu; /* private IOMMU data */
#endif
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <asm/xen/hypervisor.h>

#define DMA_ERROR_CODE (~(dma_addr_t)0)
extern struct dma_map_ops dummy_dma_ops;
extern const struct dma_map_ops dummy_dma_ops;

static inline struct dma_map_ops *__generic_dma_ops(struct device *dev)
static inline const struct dma_map_ops *__generic_dma_ops(struct device *dev)
{
if (dev && dev->archdata.dma_ops)
return dev->archdata.dma_ops;
Expand All @@ -39,7 +39,7 @@ static inline struct dma_map_ops *__generic_dma_ops(struct device *dev)
return &dummy_dma_ops;
}

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
if (xen_initial_domain())
return xen_dma_ops;
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/mm/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
return 1;
}

static struct dma_map_ops swiotlb_dma_ops = {
static const struct dma_map_ops swiotlb_dma_ops = {
.alloc = __dma_alloc,
.free = __dma_free,
.mmap = __swiotlb_mmap,
Expand Down Expand Up @@ -505,7 +505,7 @@ static int __dummy_dma_supported(struct device *hwdev, u64 mask)
return 0;
}

struct dma_map_ops dummy_dma_ops = {
const struct dma_map_ops dummy_dma_ops = {
.alloc = __dummy_alloc,
.free = __dummy_free,
.mmap = __dummy_mmap,
Expand Down Expand Up @@ -784,7 +784,7 @@ static void __iommu_unmap_sg_attrs(struct device *dev,
iommu_dma_unmap_sg(dev, sgl, nelems, dir, attrs);
}

static struct dma_map_ops iommu_dma_ops = {
static const struct dma_map_ops iommu_dma_ops = {
.alloc = __iommu_alloc_attrs,
.free = __iommu_free_attrs,
.mmap = __iommu_mmap_attrs,
Expand Down
4 changes: 2 additions & 2 deletions arch/avr32/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
int direction);

extern struct dma_map_ops avr32_dma_ops;
extern const struct dma_map_ops avr32_dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return &avr32_dma_ops;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/avr32/mm/dma-coherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void avr32_dma_sync_sg_for_device(struct device *dev,
dma_cache_sync(dev, sg_virt(sg), sg->length, direction);
}

struct dma_map_ops avr32_dma_ops = {
const struct dma_map_ops avr32_dma_ops = {
.alloc = avr32_dma_alloc,
.free = avr32_dma_free,
.map_page = avr32_dma_map_page,
Expand Down
4 changes: 2 additions & 2 deletions arch/blackfin/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ _dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir)
__dma_sync(addr, size, dir);
}

extern struct dma_map_ops bfin_dma_ops;
extern const struct dma_map_ops bfin_dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return &bfin_dma_ops;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/blackfin/kernel/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static inline void bfin_dma_sync_single_for_device(struct device *dev,
_dma_sync(handle, size, dir);
}

struct dma_map_ops bfin_dma_ops = {
const struct dma_map_ops bfin_dma_ops = {
.alloc = bfin_dma_alloc,
.free = bfin_dma_free,

Expand Down
4 changes: 2 additions & 2 deletions arch/c6x/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
#define DMA_ERROR_CODE ~0

extern struct dma_map_ops c6x_dma_ops;
extern const struct dma_map_ops c6x_dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return &c6x_dma_ops;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/c6x/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static void c6x_dma_sync_sg_for_device(struct device *dev,

}

struct dma_map_ops c6x_dma_ops = {
const struct dma_map_ops c6x_dma_ops = {
.alloc = c6x_dma_alloc,
.free = c6x_dma_free,
.map_page = c6x_dma_map_page,
Expand Down
2 changes: 1 addition & 1 deletion arch/cris/arch-v32/drivers/pci/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static inline int v32_dma_supported(struct device *dev, u64 mask)
return 1;
}

struct dma_map_ops v32_dma_ops = {
const struct dma_map_ops v32_dma_ops = {
.alloc = v32_dma_alloc,
.free = v32_dma_free,
.map_page = v32_dma_map_page,
Expand Down
6 changes: 3 additions & 3 deletions arch/cris/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define _ASM_CRIS_DMA_MAPPING_H

#ifdef CONFIG_PCI
extern struct dma_map_ops v32_dma_ops;
extern const struct dma_map_ops v32_dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return &v32_dma_ops;
}
#else
static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
BUG();
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions arch/frv/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
extern unsigned long __nongprelbss dma_coherent_mem_start;
extern unsigned long __nongprelbss dma_coherent_mem_end;

extern struct dma_map_ops frv_dma_ops;
extern const struct dma_map_ops frv_dma_ops;

static inline struct dma_map_ops *get_dma_ops(struct device *dev)
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
{
return &frv_dma_ops;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/frv/mb93090-mb00/pci-dma-nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static int frv_dma_supported(struct device *dev, u64 mask)
return 1;
}

struct dma_map_ops frv_dma_ops = {
const struct dma_map_ops frv_dma_ops = {
.alloc = frv_dma_alloc,
.free = frv_dma_free,
.map_page = frv_dma_map_page,
Expand Down
Loading

0 comments on commit 5299709

Please sign in to comment.