| 1 |
/* Reduced from linux-5.10.162's drivers-base-bus.c */ |
| 2 |
/* { dg-additional-options "-fno-delete-null-pointer-checks -O2" } */ |
| 3 |
|
| 4 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 5 |
|
| 6 |
|
| 7 |
typedef unsigned int __kernel_size_t; |
| 8 |
typedef int __kernel_ssize_t; |
| 9 |
typedef __kernel_size_t size_t; |
| 10 |
typedef __kernel_ssize_t ssize_t; |
| 11 |
|
| 12 |
struct list_head |
| 13 |
{ |
| 14 |
struct list_head *next, *prev; |
| 15 |
}; |
| 16 |
|
| 17 |
struct kobject |
| 18 |
{ |
| 19 |
/* [...snip...] */ |
| 20 |
}; |
| 21 |
|
| 22 |
struct attribute |
| 23 |
{ |
| 24 |
/* [...snip...] */ |
| 25 |
}; |
| 26 |
|
| 27 |
static inline |
| 28 |
void |
| 29 |
sysfs_remove_file_ns(struct kobject* kobj, |
| 30 |
const struct attribute* attr, |
| 31 |
const void* ns) |
| 32 |
{ |
| 33 |
} |
| 34 |
|
| 35 |
static inline |
| 36 |
void |
| 37 |
sysfs_remove_file(struct kobject* kobj, const struct attribute* attr) |
| 38 |
{ |
| 39 |
sysfs_remove_file_ns(kobj, attr, NULL); |
| 40 |
} |
| 41 |
|
| 42 |
extern struct kobject* |
| 43 |
kobject_get(struct kobject* kobj); |
| 44 |
|
| 45 |
extern void |
| 46 |
kobject_put(struct kobject* kobj); |
| 47 |
|
| 48 |
struct kset |
| 49 |
{ |
| 50 |
struct list_head list; |
| 51 |
/* [...snip...] */ |
| 52 |
struct kobject kobj; |
| 53 |
/* [...snip...] */ |
| 54 |
} __attribute__((__designated_init__)); |
| 55 |
|
| 56 |
static inline |
| 57 |
struct kset* |
| 58 |
to_kset(struct kobject* kobj) |
| 59 |
{ |
| 60 |
return kobj ? ({ |
| 61 |
char* __mptr = (char*)(kobj); |
| 62 |
((struct kset*)(__mptr - __builtin_offsetof(struct kset, kobj))); |
| 63 |
}) : NULL; |
| 64 |
} |
| 65 |
|
| 66 |
static inline |
| 67 |
struct kset* |
| 68 |
kset_get(struct kset* k) |
| 69 |
{ |
| 70 |
return k ? to_kset(kobject_get(&k->kobj)) : NULL; |
| 71 |
} |
| 72 |
|
| 73 |
static inline |
| 74 |
void |
| 75 |
kset_put(struct kset* k) |
| 76 |
{ |
| 77 |
kobject_put(&k->kobj); |
| 78 |
} |
| 79 |
|
| 80 |
struct bus_type |
| 81 |
{ |
| 82 |
/* [...snip...] */ |
| 83 |
struct device* dev_root; |
| 84 |
/* [...snip...] */ |
| 85 |
struct subsys_private* p; |
| 86 |
/* [...snip...] */ |
| 87 |
}; |
| 88 |
|
| 89 |
struct bus_attribute |
| 90 |
{ |
| 91 |
struct attribute attr; |
| 92 |
/* [...snip...] */ |
| 93 |
}; |
| 94 |
|
| 95 |
extern void |
| 96 |
device_unregister(struct device* dev); |
| 97 |
|
| 98 |
struct subsys_private |
| 99 |
{ |
| 100 |
struct kset subsys; |
| 101 |
/* [...snip...] */ |
| 102 |
}; |
| 103 |
|
| 104 |
static struct bus_type* |
| 105 |
bus_get(struct bus_type* bus) |
| 106 |
{ |
| 107 |
if (bus) { /* { dg-bogus "check of 'bus' for NULL after already dereferencing it" } */ |
| 108 |
kset_get(&bus->p->subsys); |
| 109 |
return bus; |
| 110 |
} |
| 111 |
return NULL; |
| 112 |
} |
| 113 |
|
| 114 |
static void |
| 115 |
bus_put(struct bus_type* bus) |
| 116 |
{ |
| 117 |
if (bus) |
| 118 |
kset_put(&bus->p->subsys); |
| 119 |
} |
| 120 |
|
| 121 |
void |
| 122 |
bus_remove_file(struct bus_type* bus, struct bus_attribute* attr) |
| 123 |
{ |
| 124 |
if (bus_get(bus)) { |
| 125 |
sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); |
| 126 |
bus_put(bus); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
extern ssize_t |
| 131 |
drivers_autoprobe_show(struct bus_type* bus, char* buf); |
| 132 |
|
| 133 |
extern ssize_t |
| 134 |
drivers_autoprobe_store(struct bus_type* bus, const char* buf, size_t count); |
| 135 |
|
| 136 |
extern struct bus_attribute bus_attr_drivers_autoprobe; |
| 137 |
|
| 138 |
static void |
| 139 |
remove_probe_files(struct bus_type* bus) |
| 140 |
{ |
| 141 |
bus_remove_file(bus, &bus_attr_drivers_autoprobe); |
| 142 |
/* [...snip...] */ |
| 143 |
} |
| 144 |
|
| 145 |
void |
| 146 |
bus_unregister(struct bus_type* bus) |
| 147 |
{ |
| 148 |
/* [...snip...] */ |
| 149 |
if (bus->dev_root) /* { dg-bogus "pointer 'bus' is dereferenced here" } */ |
| 150 |
device_unregister(bus->dev_root); |
| 151 |
/* [...snip...] */ |
| 152 |
remove_probe_files(bus); |
| 153 |
/* [...snip...] */ |
| 154 |
} |