chiark / gitweb /
[PATCH] Patch from Alex Riesen <raa.lkml@gmail.com>
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 23 Nov 2004 02:43:37 +0000 (03:43 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 05:30:28 +0000 (22:30 -0700)
> I just put const's at some places. It cut down data segments, but
> increased code size.
> Overall still smaller:
>
> -rwxr-xr-x  1 user users 50420 Nov 19 10:53 ../udev-046/udev
> -rwxr-xr-x  1 user users 49556 Nov 19 10:53 udev
>    text    data     bss     dec     hex filename
>   47245     968   22480   70693   11425 ../udev-046/udev
>   48089     104   22064   70257   11271 udev
>
> Also, the instance of utsname in udev_lib.c is used only once.

udev_lib.c
udev_sysfs.c

index f388d23f3e0e2812aabb5e1fe0b9fed74895c10f..86a526f7e816ecca46aedf4dc622a355d92b7b74 100644 (file)
@@ -62,12 +62,12 @@ void udev_set_values(struct udevice *udev, const char* devpath,
 
 int kernel_release_satisfactory(int version, int patchlevel, int sublevel)
 {
-       static struct utsname uts;
        static int kversion = 0;
        static int kpatchlevel;
        static int ksublevel;
 
        if (kversion == 0) {
+               struct utsname uts;
                if (uname(&uts) != 0)
                        return -1;
 
index e2c706c6f5d6477abd60fc3899966281256e04f9..a25223ef461248242e394a7dc1b57fcdc366c36e 100644 (file)
@@ -35,9 +35,9 @@
 #include "logging.h"
 
 /* list of subsystem specific files, NULL if there is no file to wait for */
-static struct subsystem_file {
-       char *subsystem;
-       char *file;
+static const struct subsystem_file {
+       const char *subsystem;
+       const char *file;
 } subsystem_files[] = {
        { .subsystem = "net",           .file = "ifindex" },
        { .subsystem = "scsi_host",     .file = "unique_id" },
@@ -56,7 +56,7 @@ static struct subsystem_file {
 
 int subsystem_expect_no_dev(const char *subsystem)
 {
-       struct subsystem_file *file;
+       const struct subsystem_file *file;
 
        for (file = subsystem_files; file->subsystem != NULL; file++)
                if (strcmp(subsystem, file->subsystem) == 0)
@@ -66,9 +66,9 @@ int subsystem_expect_no_dev(const char *subsystem)
 }
 
 /* get subsystem specific files, returns "dev" if no other found */
-static char *get_subsystem_specific_file(const char *subsystem)
+static const char *get_subsystem_specific_file(const char *subsystem)
 {
-       struct subsystem_file *file;
+       const struct subsystem_file *file;
 
        /* look if we want to look for another file instead of "dev" */
        for (file = subsystem_files; file->subsystem != NULL; file++)
@@ -123,9 +123,9 @@ static int class_device_expect_no_device_link(struct sysfs_class_device *class_d
 {
        /* list of devices without a "device" symlink to the physical device
         * if device is set to NULL, no devices in that subsystem has a link */
-       static struct class_device {
-               char *subsystem;
-               char *device;
+       static const struct class_device {
+               const char *subsystem;
+               const char *device;
        } class_device[] = {
                { .subsystem = "block",         .device = "double" },
                { .subsystem = "block",         .device = "nb" },
@@ -202,7 +202,7 @@ static int class_device_expect_no_device_link(struct sysfs_class_device *class_d
                { .subsystem = "capi",          .device = NULL },
                { NULL, NULL }
        };
-       struct class_device *classdevice;
+       const struct class_device *classdevice;
        int len;
 
        /* the kernel may tell us what to wait for */
@@ -240,13 +240,13 @@ static int class_device_expect_no_device_link(struct sysfs_class_device *class_d
 /* skip waiting for the bus of the devices device */
 static int class_device_expect_no_bus(struct sysfs_class_device *class_dev)
 {
-       static char *devices_without_bus[] = {
+       static const char *devices_without_bus[] = {
                "scsi_host",
                "i2c-adapter",
                "i2c-dev",
                NULL
        };
-       char **device;
+       const char **device;
 
        for (device = devices_without_bus; *device != NULL; device++) {
                int len = strlen(*device);
@@ -262,9 +262,9 @@ static int class_device_expect_no_bus(struct sysfs_class_device *class_dev)
 int wait_for_devices_device(struct sysfs_device *devices_dev,
                        const char **error)
 {
-       static struct device_file {
-               char *bus;
-               char *file;
+       static const struct device_file {
+               const char *bus;
+               const char *file;
        } device_files[] = {
                { .bus = "scsi",        .file = "vendor" },
                { .bus = "usb",         .file = "idVendor" },
@@ -302,7 +302,7 @@ int wait_for_devices_device(struct sysfs_device *devices_dev,
                { .bus = "iucv",        .file = "detach_state" },
                { NULL, NULL }
        };
-       struct device_file *devicefile;
+       const struct device_file *devicefile;
        int loop;
 
        /* the kernel may tell us what to wait for */