]> www.infradead.org Git - users/willy/linux.git/commitdiff
staging: gpib: Modify gpib_register_driver() to return error if it fails
authorNihar Chaithanya <niharchaithanya@gmail.com>
Mon, 30 Dec 2024 18:56:21 +0000 (00:26 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 7 Jan 2025 14:38:54 +0000 (15:38 +0100)
The function gpib_register_driver() can fail if kmalloc() fails,
but it doesn't return any error if that happens.

Modify the function to return error i.e int. Return the appropriate
error code if it fails. Remove the pr_info() statement.

Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
Link: https://lore.kernel.org/r/20241230185633.175690-2-niharchaithanya@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gpib/common/gpib_os.c
drivers/staging/gpib/include/gpibP.h

index 405237d8cb479f25a01e6988f13ee47c8ffed822..07795df3b721df3735a7700c364422d97ffb4f48 100644 (file)
@@ -2094,18 +2094,19 @@ void init_gpib_descriptor(gpib_descriptor_t *desc)
        atomic_set(&desc->io_in_progress, 0);
 }
 
-void gpib_register_driver(gpib_interface_t *interface, struct module *provider_module)
+int gpib_register_driver(gpib_interface_t *interface, struct module *provider_module)
 {
        struct gpib_interface_list_struct *entry;
 
        entry = kmalloc(sizeof(*entry), GFP_KERNEL);
        if (!entry)
-               return;
+               return -ENOMEM;
 
        entry->interface = interface;
        entry->module = provider_module;
        list_add(&entry->list, &registered_drivers);
-       pr_info("gpib: registered %s interface\n", interface->name);
+
+       return 0;
 }
 EXPORT_SYMBOL(gpib_register_driver);
 
index 5fc42b645ab70c29ad0400188ed1a4b384a2b380..d0cd42c1a0ad65fc76b97149bf868859768fb41a 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/fs.h>
 #include <linux/interrupt.h>
 
-void gpib_register_driver(gpib_interface_t *interface, struct module *mod);
+int gpib_register_driver(gpib_interface_t *interface, struct module *mod);
 void gpib_unregister_driver(gpib_interface_t *interface);
 struct pci_dev *gpib_pci_get_device(const gpib_board_config_t *config, unsigned int vendor_id,
                                    unsigned int device_id, struct pci_dev *from);