Skip to content

Commit

Permalink
kmalloc/kzalloc changes:
Browse files Browse the repository at this point in the history
dv1394, eth1394, ieee1394, ohci1394, pcilynx, raw1394, sbp2c, video1394:
 - use kzalloc
 - provide safer size arguments to kmalloc and kzalloc
 - omit some casts

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Jody McIntyre <scjody@modernduck.com>
  • Loading branch information
Stefan Richter authored and scjody committed Nov 7, 2005
1 parent 7afa146 commit 8551158
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 143 deletions.
11 changes: 5 additions & 6 deletions drivers/ieee1394/csr1212.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
return CSR1212_EINVAL;
#endif

cr = CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
cr = CSR1212_MALLOC(sizeof(*cr));
if (!cr)
return CSR1212_ENOMEM;

Expand Down Expand Up @@ -1393,8 +1393,7 @@ int csr1212_parse_keyval(struct csr1212_keyval *kv,
case CSR1212_KV_TYPE_LEAF:
if (kv->key.id != CSR1212_KV_ID_EXTENDED_ROM) {
kv->value.leaf.data = CSR1212_MALLOC(quads_to_bytes(kvi_len));
if (!kv->value.leaf.data)
{
if (!kv->value.leaf.data) {
ret = CSR1212_ENOMEM;
goto fail;
}
Expand Down Expand Up @@ -1462,7 +1461,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
cache->next = NULL;
csr->cache_tail = cache;
cache->filled_head =
CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
CSR1212_MALLOC(sizeof(*cache->filled_head));
if (!cache->filled_head) {
return CSR1212_ENOMEM;
}
Expand All @@ -1484,7 +1483,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
/* Now seach read portions of the cache to see if it is there. */
for (cr = cache->filled_head; cr; cr = cr->next) {
if (cache_index < cr->offset_start) {
newcr = CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
newcr = CSR1212_MALLOC(sizeof(*newcr));
if (!newcr)
return CSR1212_ENOMEM;

Expand All @@ -1508,7 +1507,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)

if (!cr) {
cr = cache->filled_tail;
newcr = CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
newcr = CSR1212_MALLOC(sizeof(*newcr));
if (!newcr)
return CSR1212_ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee1394/csr1212.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static inline struct csr1212_csr_rom_cache *csr1212_rom_cache_malloc(u_int32_t o
{
struct csr1212_csr_rom_cache *cache;

cache = CSR1212_MALLOC(sizeof(struct csr1212_csr_rom_cache) + size);
cache = CSR1212_MALLOC(sizeof(*cache) + size);
if (!cache)
return NULL;

Expand Down
4 changes: 1 addition & 3 deletions drivers/ieee1394/dv1394.c
Original file line number Diff line number Diff line change
Expand Up @@ -2218,14 +2218,12 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes
unsigned long flags;
int i;

video = kmalloc(sizeof(struct video_card), GFP_KERNEL);
video = kzalloc(sizeof(*video), GFP_KERNEL);
if (!video) {
printk(KERN_ERR "dv1394: cannot allocate video_card\n");
goto err;
}

memset(video, 0, sizeof(struct video_card));

video->ohci = ohci;
/* lower 2 bits of id indicate which of four "plugs"
per host */
Expand Down
12 changes: 6 additions & 6 deletions drivers/ieee1394/eth1394.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ static int eth1394_probe(struct device *dev)
if (!hi)
return -ENOENT;

new_node = kmalloc(sizeof(struct eth1394_node_ref),
new_node = kmalloc(sizeof(*new_node),
in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if (!new_node)
return -ENOMEM;

node_info = kmalloc(sizeof(struct eth1394_node_info),
node_info = kmalloc(sizeof(*node_info),
in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if (!node_info) {
kfree(new_node);
Expand Down Expand Up @@ -433,12 +433,12 @@ static int eth1394_update(struct unit_directory *ud)
node = eth1394_find_node(&priv->ip_node_list, ud);

if (!node) {
node = kmalloc(sizeof(struct eth1394_node_ref),
node = kmalloc(sizeof(*node),
in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if (!node)
return -ENOMEM;

node_info = kmalloc(sizeof(struct eth1394_node_info),
node_info = kmalloc(sizeof(*node_info),
in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if (!node_info) {
kfree(node);
Expand Down Expand Up @@ -1014,7 +1014,7 @@ static inline int new_fragment(struct list_head *frag_info, int offset, int len)
}
}

new = kmalloc(sizeof(struct fragment_info), GFP_ATOMIC);
new = kmalloc(sizeof(*new), GFP_ATOMIC);
if (!new)
return -ENOMEM;

Expand All @@ -1033,7 +1033,7 @@ static inline int new_partial_datagram(struct net_device *dev,
{
struct partial_datagram *new;

new = kmalloc(sizeof(struct partial_datagram), GFP_ATOMIC);
new = kmalloc(sizeof(*new), GFP_ATOMIC);
if (!new)
return -ENOMEM;

Expand Down
18 changes: 6 additions & 12 deletions drivers/ieee1394/highlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
return NULL;
}

hi = kmalloc(sizeof(*hi) + data_size, GFP_ATOMIC);
hi = kzalloc(sizeof(*hi) + data_size, GFP_ATOMIC);
if (!hi)
return NULL;

memset(hi, 0, sizeof(*hi) + data_size);

if (data_size) {
data = hi->data = hi + 1;
hi->size = data_size;
Expand Down Expand Up @@ -326,11 +324,9 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
return retval;
}

as = (struct hpsb_address_serve *)
kmalloc(sizeof(struct hpsb_address_serve), GFP_KERNEL);
if (as == NULL) {
as = kmalloc(sizeof(*as), GFP_KERNEL);
if (!as)
return retval;
}

INIT_LIST_HEAD(&as->host_list);
INIT_LIST_HEAD(&as->hl_list);
Expand Down Expand Up @@ -383,11 +379,9 @@ int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
return 0;
}

as = (struct hpsb_address_serve *)
kmalloc(sizeof(struct hpsb_address_serve), GFP_ATOMIC);
if (as == NULL) {
return 0;
}
as = kmalloc(sizeof(*as), GFP_ATOMIC);
if (!as)
return 0;

INIT_LIST_HEAD(&as->host_list);
INIT_LIST_HEAD(&as->hl_list);
Expand Down
6 changes: 3 additions & 3 deletions drivers/ieee1394/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
int i;
int hostnum = 0;

h = kmalloc(sizeof(struct hpsb_host) + extra, SLAB_KERNEL);
if (!h) return NULL;
memset(h, 0, sizeof(struct hpsb_host) + extra);
h = kzalloc(sizeof(*h) + extra, SLAB_KERNEL);
if (!h)
return NULL;

h->csr.rom = csr1212_create_csr(&csr_bus_ops, CSR_BUS_INFO_SIZE, h);
if (!h->csr.rom) {
Expand Down
27 changes: 12 additions & 15 deletions drivers/ieee1394/nodemgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,21 +743,20 @@ static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr
unsigned int generation)
{
struct hpsb_host *host = hi->host;
struct node_entry *ne;

ne = kmalloc(sizeof(struct node_entry), GFP_KERNEL);
if (!ne) return NULL;
struct node_entry *ne;

memset(ne, 0, sizeof(struct node_entry));
ne = kzalloc(sizeof(*ne), GFP_KERNEL);
if (!ne)
return NULL;

ne->tpool = &host->tpool[nodeid & NODE_MASK];

ne->host = host;
ne->nodeid = nodeid;
ne->host = host;
ne->nodeid = nodeid;
ne->generation = generation;
ne->needs_probe = 1;

ne->guid = guid;
ne->guid = guid;
ne->guid_vendor_id = (guid >> 40) & 0xffffff;
ne->guid_vendor_oui = nodemgr_find_oui_name(ne->guid_vendor_id);
ne->csr = csr;
Expand Down Expand Up @@ -787,7 +786,7 @@ static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr
(host->node_id == nodeid) ? "Host" : "Node",
NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid);

return ne;
return ne;
}


Expand Down Expand Up @@ -872,12 +871,10 @@ static struct unit_directory *nodemgr_process_unit_directory
struct csr1212_keyval *kv;
u8 last_key_id = 0;

ud = kmalloc(sizeof(struct unit_directory), GFP_KERNEL);
ud = kzalloc(sizeof(*ud), GFP_KERNEL);
if (!ud)
goto unit_directory_error;

memset (ud, 0, sizeof(struct unit_directory));

ud->ne = ne;
ud->ignore_driver = ignore_drivers;
ud->address = ud_kv->offset + CSR1212_CONFIG_ROM_SPACE_BASE;
Expand Down Expand Up @@ -937,10 +934,10 @@ static struct unit_directory *nodemgr_process_unit_directory
/* Logical Unit Number */
if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) {
if (ud->flags & UNIT_DIRECTORY_HAS_LUN) {
ud_child = kmalloc(sizeof(struct unit_directory), GFP_KERNEL);
ud_child = kmalloc(sizeof(*ud_child), GFP_KERNEL);
if (!ud_child)
goto unit_directory_error;
memcpy(ud_child, ud, sizeof(struct unit_directory));
memcpy(ud_child, ud, sizeof(*ud_child));
nodemgr_register_device(ne, ud_child, &ne->device);
ud_child = NULL;

Expand Down Expand Up @@ -1200,7 +1197,7 @@ static void nodemgr_node_scan_one(struct host_info *hi,
struct csr1212_csr *csr;
struct nodemgr_csr_info *ci;

ci = kmalloc(sizeof(struct nodemgr_csr_info), GFP_KERNEL);
ci = kmalloc(sizeof(*ci), GFP_KERNEL);
if (!ci)
return;

Expand Down
20 changes: 6 additions & 14 deletions drivers/ieee1394/ohci1394.c
Original file line number Diff line number Diff line change
Expand Up @@ -2957,28 +2957,23 @@ alloc_dma_rcv_ctx(struct ti_ohci *ohci, struct dma_rcv_ctx *d,
d->ctrlClear = 0;
d->cmdPtr = 0;

d->buf_cpu = kmalloc(d->num_desc * sizeof(quadlet_t*), GFP_ATOMIC);
d->buf_bus = kmalloc(d->num_desc * sizeof(dma_addr_t), GFP_ATOMIC);
d->buf_cpu = kzalloc(d->num_desc * sizeof(*d->buf_cpu), GFP_ATOMIC);
d->buf_bus = kzalloc(d->num_desc * sizeof(*d->buf_bus), GFP_ATOMIC);

if (d->buf_cpu == NULL || d->buf_bus == NULL) {
PRINT(KERN_ERR, "Failed to allocate dma buffer");
free_dma_rcv_ctx(d);
return -ENOMEM;
}
memset(d->buf_cpu, 0, d->num_desc * sizeof(quadlet_t*));
memset(d->buf_bus, 0, d->num_desc * sizeof(dma_addr_t));

d->prg_cpu = kmalloc(d->num_desc * sizeof(struct dma_cmd*),
GFP_ATOMIC);
d->prg_bus = kmalloc(d->num_desc * sizeof(dma_addr_t), GFP_ATOMIC);
d->prg_cpu = kzalloc(d->num_desc * sizeof(*d->prg_cpu), GFP_ATOMIC);
d->prg_bus = kzalloc(d->num_desc * sizeof(*d->prg_bus), GFP_ATOMIC);

if (d->prg_cpu == NULL || d->prg_bus == NULL) {
PRINT(KERN_ERR, "Failed to allocate dma prg");
free_dma_rcv_ctx(d);
return -ENOMEM;
}
memset(d->prg_cpu, 0, d->num_desc * sizeof(struct dma_cmd*));
memset(d->prg_bus, 0, d->num_desc * sizeof(dma_addr_t));

d->spb = kmalloc(d->split_buf_size, GFP_ATOMIC);

Expand Down Expand Up @@ -3090,17 +3085,14 @@ alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d,
d->ctrlClear = 0;
d->cmdPtr = 0;

d->prg_cpu = kmalloc(d->num_desc * sizeof(struct at_dma_prg*),
GFP_KERNEL);
d->prg_bus = kmalloc(d->num_desc * sizeof(dma_addr_t), GFP_KERNEL);
d->prg_cpu = kzalloc(d->num_desc * sizeof(*d->prg_cpu), GFP_KERNEL);
d->prg_bus = kzalloc(d->num_desc * sizeof(*d->prg_bus), GFP_KERNEL);

if (d->prg_cpu == NULL || d->prg_bus == NULL) {
PRINT(KERN_ERR, "Failed to allocate at dma prg");
free_dma_trm_ctx(d);
return -ENOMEM;
}
memset(d->prg_cpu, 0, d->num_desc * sizeof(struct at_dma_prg*));
memset(d->prg_bus, 0, d->num_desc * sizeof(dma_addr_t));

len = sprintf(pool_name, "ohci1394_trm_prg");
sprintf(pool_name+len, "%d", num_allocs);
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee1394/pcilynx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ static int __devinit add_card(struct pci_dev *dev,
struct i2c_algo_bit_data i2c_adapter_data;

error = -ENOMEM;
i2c_ad = kmalloc(sizeof(struct i2c_adapter), SLAB_KERNEL);
i2c_ad = kmalloc(sizeof(*i2c_ad), SLAB_KERNEL);
if (!i2c_ad) FAIL("failed to allocate I2C adapter memory");

memcpy(i2c_ad, &bit_ops, sizeof(struct i2c_adapter));
Expand Down
Loading

0 comments on commit 8551158

Please sign in to comment.