mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 02:39:48 +00:00
![Linus Torvalds](/assets/img/avatar_default.png)
- Use overflow helpers in 2-factor allocators (Kees, Rasmus) - Introduce overflow test module (Rasmus, Kees) - Introduce saturating size helper functions (Matthew, Kees) - Treewide use of struct_size() for allocators (Kees) -----BEGIN PGP SIGNATURE----- Comment: Kees Cook <kees@outflux.net> iQJKBAABCgA0FiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAlsYJ1gWHGtlZXNjb29r QGNocm9taXVtLm9yZwAKCRCJcvTf3G3AJlCTEACwdEeriAd2VwxknnsstojGD/3g 8TTFA19vSu4Gxa6WiDkjGoSmIlfhXTlZo1Nlmencv16ytSvIVDNLUIB3uDxUIv1J 2+dyHML9JpXYHHR7zLXXnGFJL0wazqjbsD3NYQgXqmun7EVVYnOsAlBZ7h/Lwiej jzEJd8DaHT3TA586uD3uggiFvQU0yVyvkDCDONIytmQx+BdtGdg9TYCzkBJaXuDZ YIthyKDvxIw5nh/UaG3L+SKo73tUr371uAWgAfqoaGQQCWe+mxnWL4HkCKsjFzZL u9ouxxF/n6pij3E8n6rb0i2fCzlsTDdDF+aqV1rQ4I4hVXCFPpHUZgjDPvBWbj7A m6AfRHVNnOgI8HGKqBGOfViV+2kCHlYeQh3pPW33dWzy/4d/uq9NIHKxE63LH+S4 bY3oO2ela8oxRyvEgXLjqmRYGW1LB/ZU7FS6Rkx2gRzo4k8Rv+8K/KzUHfFVRX61 jEbiPLzko0xL9D53kcEn0c+BhofK5jgeSWxItdmfuKjLTW4jWhLRlU+bcUXb6kSS S3G6aF+L+foSUwoq63AS8QxCuabuhreJSB+BmcGUyjthCbK/0WjXYC6W/IJiRfBa 3ZTxBC/2vP3uq/AGRNh5YZoxHL8mSxDfn62F+2cqlJTTKR/O+KyDb1cusyvk3H04 KCDVLYPxwQQqK1Mqig== =/3L8 -----END PGP SIGNATURE----- Merge tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux Pull overflow updates from Kees Cook: "This adds the new overflow checking helpers and adds them to the 2-factor argument allocators. And this adds the saturating size helpers and does a treewide replacement for the struct_size() usage. Additionally this adds the overflow testing modules to make sure everything works. I'm still working on the treewide replacements for allocators with "simple" multiplied arguments: *alloc(a * b, ...) -> *alloc_array(a, b, ...) and *zalloc(a * b, ...) -> *calloc(a, b, ...) as well as the more complex cases, but that's separable from this portion of the series. I expect to have the rest sent before -rc1 closes; there are a lot of messy cases to clean up. Summary: - Introduce arithmetic overflow test helper functions (Rasmus) - Use overflow helpers in 2-factor allocators (Kees, Rasmus) - Introduce overflow test module (Rasmus, Kees) - Introduce saturating size helper functions (Matthew, Kees) - Treewide use of struct_size() for allocators (Kees)" * tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: treewide: Use struct_size() for devm_kmalloc() and friends treewide: Use struct_size() for vmalloc()-family treewide: Use struct_size() for kmalloc()-family device: Use overflow helpers for devm_kmalloc() mm: Use overflow helpers in kvmalloc() mm: Use overflow helpers in kmalloc_array*() test_overflow: Add memory allocation overflow tests overflow.h: Add allocation size calculation helpers test_overflow: Report test failures test_overflow: macrofy some more, do more tests for free lib: add runtime test of check_*_overflow functions compiler.h: enable builtin overflow checkers and add fallback code
246 lines
5.6 KiB
C
246 lines
5.6 KiB
C
/*
|
|
* Zorro Bus Services
|
|
*
|
|
* Copyright (C) 1995-2003 Geert Uytterhoeven
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file COPYING in the main directory of this archive
|
|
* for more details.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/zorro.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/string.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
#include <asm/setup.h>
|
|
#include <asm/amigahw.h>
|
|
|
|
#include "zorro.h"
|
|
|
|
|
|
/*
|
|
* Zorro Expansion Devices
|
|
*/
|
|
|
|
unsigned int zorro_num_autocon;
|
|
struct zorro_dev_init zorro_autocon_init[ZORRO_NUM_AUTO] __initdata;
|
|
struct zorro_dev *zorro_autocon;
|
|
|
|
|
|
/*
|
|
* Zorro bus
|
|
*/
|
|
|
|
struct zorro_bus {
|
|
struct device dev;
|
|
struct zorro_dev devices[0];
|
|
};
|
|
|
|
|
|
/*
|
|
* Find Zorro Devices
|
|
*/
|
|
|
|
struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
|
|
{
|
|
struct zorro_dev *z;
|
|
|
|
if (!zorro_num_autocon)
|
|
return NULL;
|
|
|
|
for (z = from ? from+1 : &zorro_autocon[0];
|
|
z < zorro_autocon+zorro_num_autocon;
|
|
z++)
|
|
if (id == ZORRO_WILDCARD || id == z->id)
|
|
return z;
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(zorro_find_device);
|
|
|
|
|
|
/*
|
|
* Bitmask indicating portions of available Zorro II RAM that are unused
|
|
* by the system. Every bit represents a 64K chunk, for a maximum of 8MB
|
|
* (128 chunks, physical 0x00200000-0x009fffff).
|
|
*
|
|
* If you want to use (= allocate) portions of this RAM, you should clear
|
|
* the corresponding bits.
|
|
*
|
|
* Possible uses:
|
|
* - z2ram device
|
|
* - SCSI DMA bounce buffers
|
|
*
|
|
* FIXME: use the normal resource management
|
|
*/
|
|
|
|
DECLARE_BITMAP(zorro_unused_z2ram, 128);
|
|
EXPORT_SYMBOL(zorro_unused_z2ram);
|
|
|
|
|
|
static void __init mark_region(unsigned long start, unsigned long end,
|
|
int flag)
|
|
{
|
|
if (flag)
|
|
start += Z2RAM_CHUNKMASK;
|
|
else
|
|
end += Z2RAM_CHUNKMASK;
|
|
start &= ~Z2RAM_CHUNKMASK;
|
|
end &= ~Z2RAM_CHUNKMASK;
|
|
|
|
if (end <= Z2RAM_START || start >= Z2RAM_END)
|
|
return;
|
|
start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
|
|
end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
|
|
while (start < end) {
|
|
u32 chunk = start>>Z2RAM_CHUNKSHIFT;
|
|
|
|
if (flag)
|
|
set_bit(chunk, zorro_unused_z2ram);
|
|
else
|
|
clear_bit(chunk, zorro_unused_z2ram);
|
|
start += Z2RAM_CHUNKSIZE;
|
|
}
|
|
}
|
|
|
|
|
|
static struct resource __init *zorro_find_parent_resource(
|
|
struct platform_device *bridge, struct zorro_dev *z)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < bridge->num_resources; i++) {
|
|
struct resource *r = &bridge->resource[i];
|
|
|
|
if (zorro_resource_start(z) >= r->start &&
|
|
zorro_resource_end(z) <= r->end)
|
|
return r;
|
|
}
|
|
return &iomem_resource;
|
|
}
|
|
|
|
|
|
|
|
static int __init amiga_zorro_probe(struct platform_device *pdev)
|
|
{
|
|
struct zorro_bus *bus;
|
|
struct zorro_dev_init *zi;
|
|
struct zorro_dev *z;
|
|
struct resource *r;
|
|
unsigned int i;
|
|
int error;
|
|
|
|
/* Initialize the Zorro bus */
|
|
bus = kzalloc(struct_size(bus, devices, zorro_num_autocon),
|
|
GFP_KERNEL);
|
|
if (!bus)
|
|
return -ENOMEM;
|
|
|
|
zorro_autocon = bus->devices;
|
|
bus->dev.parent = &pdev->dev;
|
|
dev_set_name(&bus->dev, zorro_bus_type.name);
|
|
error = device_register(&bus->dev);
|
|
if (error) {
|
|
pr_err("Zorro: Error registering zorro_bus\n");
|
|
put_device(&bus->dev);
|
|
kfree(bus);
|
|
return error;
|
|
}
|
|
platform_set_drvdata(pdev, bus);
|
|
|
|
pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
|
|
zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
|
|
|
|
/* First identify all devices ... */
|
|
for (i = 0; i < zorro_num_autocon; i++) {
|
|
zi = &zorro_autocon_init[i];
|
|
z = &zorro_autocon[i];
|
|
|
|
z->rom = zi->rom;
|
|
z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) |
|
|
(z->rom.er_Product << 8);
|
|
if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
|
|
/* GVP quirk */
|
|
unsigned long magic = zi->boardaddr + 0x8000;
|
|
|
|
z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
|
|
}
|
|
z->slotaddr = zi->slotaddr;
|
|
z->slotsize = zi->slotsize;
|
|
sprintf(z->name, "Zorro device %08x", z->id);
|
|
zorro_name_device(z);
|
|
z->resource.start = zi->boardaddr;
|
|
z->resource.end = zi->boardaddr + zi->boardsize - 1;
|
|
z->resource.name = z->name;
|
|
r = zorro_find_parent_resource(pdev, z);
|
|
error = request_resource(r, &z->resource);
|
|
if (error)
|
|
dev_err(&bus->dev,
|
|
"Address space collision on device %s %pR\n",
|
|
z->name, &z->resource);
|
|
z->dev.parent = &bus->dev;
|
|
z->dev.bus = &zorro_bus_type;
|
|
z->dev.id = i;
|
|
switch (z->rom.er_Type & ERT_TYPEMASK) {
|
|
case ERT_ZORROIII:
|
|
z->dev.coherent_dma_mask = DMA_BIT_MASK(32);
|
|
break;
|
|
|
|
case ERT_ZORROII:
|
|
default:
|
|
z->dev.coherent_dma_mask = DMA_BIT_MASK(24);
|
|
break;
|
|
}
|
|
z->dev.dma_mask = &z->dev.coherent_dma_mask;
|
|
}
|
|
|
|
/* ... then register them */
|
|
for (i = 0; i < zorro_num_autocon; i++) {
|
|
z = &zorro_autocon[i];
|
|
error = device_register(&z->dev);
|
|
if (error) {
|
|
dev_err(&bus->dev, "Error registering device %s\n",
|
|
z->name);
|
|
put_device(&z->dev);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
/* Mark all available Zorro II memory */
|
|
zorro_for_each_dev(z) {
|
|
if (z->rom.er_Type & ERTF_MEMLIST)
|
|
mark_region(zorro_resource_start(z),
|
|
zorro_resource_end(z)+1, 1);
|
|
}
|
|
|
|
/* Unmark all used Zorro II memory */
|
|
for (i = 0; i < m68k_num_memory; i++)
|
|
if (m68k_memory[i].addr < 16*1024*1024)
|
|
mark_region(m68k_memory[i].addr,
|
|
m68k_memory[i].addr+m68k_memory[i].size,
|
|
0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver amiga_zorro_driver = {
|
|
.driver = {
|
|
.name = "amiga-zorro",
|
|
},
|
|
};
|
|
|
|
static int __init amiga_zorro_init(void)
|
|
{
|
|
return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
|
|
}
|
|
|
|
module_init(amiga_zorro_init);
|
|
|
|
MODULE_LICENSE("GPL");
|