Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

uio: uio_sercos3: use device-managed functions for simple allocs

This change converts the simple allocations [kzalloc()] to devm_kzalloc()
tying the life-time of these objects to the PCI device object.
It cleans up the error and exit path and bit, and does a minor correction
that -ENOMEM is returned (vs -ENODEV) in case the 'priv' object cannot be
allocated.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20201120084207.50736-1-alexandru.ardelean@analog.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alexandru Ardelean and committed by
Greg Kroah-Hartman
023c9c6d ba022851

+4 -10
+4 -10
drivers/uio/uio_sercos3.c
··· 124 124 struct sercos3_priv *priv; 125 125 int i; 126 126 127 - info = kzalloc(sizeof(struct uio_info), GFP_KERNEL); 127 + info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL); 128 128 if (!info) 129 129 return -ENOMEM; 130 130 131 - priv = kzalloc(sizeof(struct sercos3_priv), GFP_KERNEL); 131 + priv = devm_kzalloc(&dev->dev, sizeof(struct sercos3_priv), GFP_KERNEL); 132 132 if (!priv) 133 - goto out_free; 133 + return -ENOMEM; 134 134 135 135 if (pci_enable_device(dev)) 136 - goto out_free_priv; 136 + return -ENODEV; 137 137 138 138 if (pci_request_regions(dev, "sercos3")) 139 139 goto out_disable; ··· 174 174 pci_release_regions(dev); 175 175 out_disable: 176 176 pci_disable_device(dev); 177 - out_free_priv: 178 - kfree(priv); 179 - out_free: 180 - kfree(info); 181 177 return -ENODEV; 182 178 } 183 179 ··· 189 193 if (info->mem[i].internal_addr) 190 194 iounmap(info->mem[i].internal_addr); 191 195 } 192 - kfree(info->priv); 193 - kfree(info); 194 196 } 195 197 196 198 static struct pci_device_id sercos3_pci_ids[] = {