Skip to content

Commit

Permalink
[PATCH] kfree cleanup: misc remaining drivers
Browse files Browse the repository at this point in the history
This is the remaining misc drivers/ part of the big kfree cleanup patch.

Remove pointless checks for NULL prior to calling kfree() in misc files in
drivers/.

Signed-off-by: Jesper Juhl <[email protected]>
Acked-by: Aristeu Sergio Rozanski Filho <[email protected]>
Acked-by: Roland Dreier <[email protected]>
Acked-by: Pierre Ossman <[email protected]>
Acked-by: Jean Delvare <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
Acked-by: Len Brown <[email protected]>
Acked-by: "Antonino A. Daplas" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Jesper Juhl authored and Linus Torvalds committed Nov 7, 2005
1 parent 2ea7533 commit 6044ec8
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 151 deletions.
6 changes: 2 additions & 4 deletions drivers/acpi/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ static int acpi_container_remove(struct acpi_device *device, int type)
{
acpi_status status = AE_OK;
struct acpi_container *pc = NULL;
pc = (struct acpi_container *)acpi_driver_data(device);

if (pc)
kfree(pc);

pc = (struct acpi_container *)acpi_driver_data(device);
kfree(pc);
return status;
}

Expand Down
6 changes: 2 additions & 4 deletions drivers/acpi/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ static int acpi_bus_trim(struct acpi_device *start, int rmdevice);
static void acpi_device_release(struct kobject *kobj)
{
struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj);
if (dev->pnp.cid_list)
kfree(dev->pnp.cid_list);
kfree(dev->pnp.cid_list);
kfree(dev);
}

Expand Down Expand Up @@ -1117,8 +1116,7 @@ acpi_add_single_object(struct acpi_device **child,
if (!result)
*child = device;
else {
if (device->pnp.cid_list)
kfree(device->pnp.cid_list);
kfree(device->pnp.cid_list);
kfree(device);
}

Expand Down
12 changes: 4 additions & 8 deletions drivers/acpi/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
return_VALUE(0);

err:
if (buffer.pointer)
kfree(buffer.pointer);
kfree(buffer.pointer);

return_VALUE(status);
}
Expand Down Expand Up @@ -1488,8 +1487,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
}
active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;

if (video->attached_array)
kfree(video->attached_array);
kfree(video->attached_array);

video->attached_array = active_device_list;
video->attached_count = count;
Expand Down Expand Up @@ -1645,8 +1643,7 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
printk(KERN_WARNING PREFIX
"hhuuhhuu bug in acpi video driver.\n");

if (data->brightness)
kfree(data->brightness);
kfree(data->brightness);

kfree(data);
}
Expand Down Expand Up @@ -1831,8 +1828,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
acpi_video_bus_put_devices(video);
acpi_video_bus_remove_fs(device);

if (video->attached_array)
kfree(video->attached_array);
kfree(video->attached_array);
kfree(video);

return_VALUE(0);
Expand Down
31 changes: 11 additions & 20 deletions drivers/block/DAC960.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,12 @@ static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
* Remember the beginning of the group, but don't free it
* until we've reached the beginning of the next group.
*/
if (CommandGroup != NULL)
kfree(CommandGroup);
CommandGroup = Command;
kfree(CommandGroup);
CommandGroup = Command;
}
Controller->Commands[i] = NULL;
}
if (CommandGroup != NULL)
kfree(CommandGroup);
kfree(CommandGroup);

if (Controller->CombinedStatusBuffer != NULL)
{
Expand All @@ -435,30 +433,23 @@ static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)

if (ScatterGatherPool != NULL)
pci_pool_destroy(ScatterGatherPool);
if (Controller->FirmwareType == DAC960_V1_Controller) return;
if (Controller->FirmwareType == DAC960_V1_Controller)
return;

if (RequestSensePool != NULL)
pci_pool_destroy(RequestSensePool);

for (i = 0; i < DAC960_MaxLogicalDrives; i++)
if (Controller->V2.LogicalDeviceInformation[i] != NULL)
{
for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
kfree(Controller->V2.LogicalDeviceInformation[i]);
Controller->V2.LogicalDeviceInformation[i] = NULL;
}
}

for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
{
if (Controller->V2.PhysicalDeviceInformation[i] != NULL)
{
kfree(Controller->V2.PhysicalDeviceInformation[i]);
Controller->V2.PhysicalDeviceInformation[i] = NULL;
}
if (Controller->V2.InquiryUnitSerialNumber[i] != NULL)
{
kfree(Controller->V2.InquiryUnitSerialNumber[i]);
Controller->V2.InquiryUnitSerialNumber[i] = NULL;
}
kfree(Controller->V2.PhysicalDeviceInformation[i]);
Controller->V2.PhysicalDeviceInformation[i] = NULL;
kfree(Controller->V2.InquiryUnitSerialNumber[i]);
Controller->V2.InquiryUnitSerialNumber[i] = NULL;
}
}

Expand Down
12 changes: 4 additions & 8 deletions drivers/block/cciss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,14 +1096,11 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
cleanup1:
if (buff) {
for(i=0; i<sg_used; i++)
if(buff[i] != NULL)
kfree(buff[i]);
kfree(buff[i]);
kfree(buff);
}
if (buff_size)
kfree(buff_size);
if (ioc)
kfree(ioc);
kfree(buff_size);
kfree(ioc);
return(status);
}
default:
Expand Down Expand Up @@ -3034,8 +3031,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
return(1);

clean4:
if(hba[i]->cmd_pool_bits)
kfree(hba[i]->cmd_pool_bits);
kfree(hba[i]->cmd_pool_bits);
if(hba[i]->cmd_pool)
pci_free_consistent(hba[i]->pdev,
NR_CMDS * sizeof(CommandList_struct),
Expand Down
5 changes: 2 additions & 3 deletions drivers/fc4/fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ int fcp_initialize(fc_channel *fcchain, int count)
l->logi = kzalloc (count * 3 * sizeof(logi), GFP_KERNEL);
l->fcmds = kzalloc (count * sizeof(fcp_cmnd), GFP_KERNEL);
if (!l->logi || !l->fcmds) {
if (l->logi) kfree (l->logi);
if (l->fcmds) kfree (l->fcmds);
kfree (l->logi);
kfree (l->fcmds);
kfree (l);
printk ("FC: Cannot allocate DMA memory for initialization\n");
return -ENOMEM;
Expand Down Expand Up @@ -674,7 +674,6 @@ int fcp_forceoffline(fc_channel *fcchain, int count)
atomic_set (&l.todo, count);
l.fcmds = kzalloc (count * sizeof(fcp_cmnd), GFP_KERNEL);
if (!l.fcmds) {
kfree (l.fcmds);
printk ("FC: Cannot allocate memory for forcing offline\n");
return -ENOMEM;
}
Expand Down
6 changes: 2 additions & 4 deletions drivers/hwmon/w83781d.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,11 +976,9 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
ERROR_SC_3:
i2c_detach_client(data->lm75[0]);
ERROR_SC_2:
if (data->lm75[1])
kfree(data->lm75[1]);
kfree(data->lm75[1]);
ERROR_SC_1:
if (data->lm75[0])
kfree(data->lm75[0]);
kfree(data->lm75[0]);
ERROR_SC_0:
return err;
}
Expand Down
6 changes: 2 additions & 4 deletions drivers/i2c/busses/i2c-amd756-s4882.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,8 @@ static void __exit amd756_s4882_exit(void)
kfree(s4882_adapter);
s4882_adapter = NULL;
}
if (s4882_algo) {
kfree(s4882_algo);
s4882_algo = NULL;
}
kfree(s4882_algo);
s4882_algo = NULL;

/* Restore physical bus */
if (i2c_add_adapter(&amd756_smbus))
Expand Down
18 changes: 6 additions & 12 deletions drivers/ide/ide-cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3292,12 +3292,9 @@ static void ide_cd_release(struct kref *kref)
ide_drive_t *drive = info->drive;
struct gendisk *g = info->disk;

if (info->buffer != NULL)
kfree(info->buffer);
if (info->toc != NULL)
kfree(info->toc);
if (info->changer_info != NULL)
kfree(info->changer_info);
kfree(info->buffer);
kfree(info->toc);
kfree(info->changer_info);
if (devinfo->handle == drive && unregister_cdrom(devinfo))
printk(KERN_ERR "%s: %s failed to unregister device from the cdrom "
"driver.\n", __FUNCTION__, drive->name);
Expand Down Expand Up @@ -3487,12 +3484,9 @@ static int ide_cd_probe(struct device *dev)
if (ide_cdrom_setup(drive)) {
struct cdrom_device_info *devinfo = &info->devinfo;
ide_unregister_subdriver(drive, &ide_cdrom_driver);
if (info->buffer != NULL)
kfree(info->buffer);
if (info->toc != NULL)
kfree(info->toc);
if (info->changer_info != NULL)
kfree(info->changer_info);
kfree(info->buffer);
kfree(info->toc);
kfree(info->changer_info);
if (devinfo->handle == drive && unregister_cdrom(devinfo))
printk (KERN_ERR "%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name);
kfree(info);
Expand Down
6 changes: 2 additions & 4 deletions drivers/ide/ide-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,10 +1315,8 @@ static void drive_release_dev (struct device *dev)
drive->devfs_name[0] = '\0';
}
ide_remove_drive_from_hwgroup(drive);
if (drive->id != NULL) {
kfree(drive->id);
drive->id = NULL;
}
kfree(drive->id);
drive->id = NULL;
drive->present = 0;
/* Messed up locking ... */
spin_unlock_irq(&ide_lock);
Expand Down
6 changes: 2 additions & 4 deletions drivers/ide/ide-taskfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,8 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
}
abort:
kfree(req_task);
if (outbuf != NULL)
kfree(outbuf);
if (inbuf != NULL)
kfree(inbuf);
kfree(outbuf);
kfree(inbuf);

// printk("IDE Taskfile ioctl ended. rc = %i\n", err);

Expand Down
3 changes: 1 addition & 2 deletions drivers/ide/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,7 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int r
return 0;
abort:
up(&ide_setting_sem);
if (setting)
kfree(setting);
kfree(setting);
return -1;
}

Expand Down
6 changes: 2 additions & 4 deletions drivers/infiniband/core/mad.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
wait_event(mad_agent_priv->wait,
!atomic_read(&mad_agent_priv->refcount));

if (mad_agent_priv->reg_req)
kfree(mad_agent_priv->reg_req);
kfree(mad_agent_priv->reg_req);
ib_dereg_mr(mad_agent_priv->agent.mr);
kfree(mad_agent_priv);
}
Expand Down Expand Up @@ -2500,8 +2499,7 @@ static int create_mad_qp(struct ib_mad_qp_info *qp_info,
static void destroy_mad_qp(struct ib_mad_qp_info *qp_info)
{
ib_destroy_qp(qp_info->qp);
if (qp_info->snoop_table)
kfree(qp_info->snoop_table);
kfree(qp_info->snoop_table);
}

/*
Expand Down
10 changes: 3 additions & 7 deletions drivers/input/misc/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz
goto exit;
}

if (dev->name)
kfree(dev->name);
kfree(dev->name);

size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1;
dev->name = name = kmalloc(size, GFP_KERNEL);
Expand Down Expand Up @@ -372,11 +371,8 @@ static int uinput_burn_device(struct uinput_device *udev)
if (test_bit(UIST_CREATED, &udev->state))
uinput_destroy_device(udev);

if (udev->dev->name)
kfree(udev->dev->name);
if (udev->dev->phys)
kfree(udev->dev->phys);

kfree(udev->dev->name);
kfree(udev->dev->phys);
kfree(udev->dev);
kfree(udev);

Expand Down
3 changes: 1 addition & 2 deletions drivers/macintosh/adbhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,7 @@ adbhid_input_register(int id, int default_id, int original_handler_id,
static void adbhid_input_unregister(int id)
{
input_unregister_device(adbhid[id]->input);
if (adbhid[id]->keycode)
kfree(adbhid[id]->keycode);
kfree(adbhid[id]->keycode);
kfree(adbhid[id]);
adbhid[id] = NULL;
}
Expand Down
3 changes: 1 addition & 2 deletions drivers/mmc/wbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,7 @@ static void __devexit wbsd_release_dma(struct wbsd_host* host)
if (host->dma_addr)
dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE,
DMA_BIDIRECTIONAL);
if (host->dma_buffer)
kfree(host->dma_buffer);
kfree(host->dma_buffer);
if (host->dma >= 0)
free_dma(host->dma);

Expand Down
21 changes: 10 additions & 11 deletions drivers/parport/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,15 @@ static void parse_data(struct parport *port, int device, char *str)
u++;
}
if (!strcmp(p, "MFG") || !strcmp(p, "MANUFACTURER")) {
if (info->mfr)
kfree (info->mfr);
kfree(info->mfr);
info->mfr = kstrdup(sep, GFP_KERNEL);
} else if (!strcmp(p, "MDL") || !strcmp(p, "MODEL")) {
if (info->model)
kfree (info->model);
kfree(info->model);
info->model = kstrdup(sep, GFP_KERNEL);
} else if (!strcmp(p, "CLS") || !strcmp(p, "CLASS")) {
int i;
if (info->class_name)
kfree (info->class_name);

kfree(info->class_name);
info->class_name = kstrdup(sep, GFP_KERNEL);
for (u = sep; *u; u++)
*u = toupper(*u);
Expand All @@ -102,21 +100,22 @@ static void parse_data(struct parport *port, int device, char *str)
info->class = PARPORT_CLASS_OTHER;
} else if (!strcmp(p, "CMD") ||
!strcmp(p, "COMMAND SET")) {
if (info->cmdset)
kfree (info->cmdset);
kfree(info->cmdset);
info->cmdset = kstrdup(sep, GFP_KERNEL);
/* if it speaks printer language, it's
probably a printer */
if (strstr(sep, "PJL") || strstr(sep, "PCL"))
guessed_class = PARPORT_CLASS_PRINTER;
} else if (!strcmp(p, "DES") || !strcmp(p, "DESCRIPTION")) {
if (info->description)
kfree (info->description);
kfree(info->description);
info->description = kstrdup(sep, GFP_KERNEL);
}
}
rock_on:
if (q) p = q+1; else p=NULL;
if (q)
p = q + 1;
else
p = NULL;
}

/* If the device didn't tell us its class, maybe we have managed to
Expand Down
Loading

0 comments on commit 6044ec8

Please sign in to comment.