diff options
author | Lars Ellenberg <lars.ellenberg@linbit.com> | 2014-04-28 12:43:35 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-04-30 15:46:56 -0400 |
commit | ec4a340789be16831ae96be5f7552238a7a6e903 (patch) | |
tree | 5571ed3e41b1afaaf2633dc135e62351ed162aa8 | |
parent | babea49ebe010d0a533b5db20fa63c327402a71c (diff) |
drbd: use list_first_entry_or_null in first_peer_device/first_connection
If there are no peer_devices or connections, I'd rather have NULL
than some "arbitrary" address pretending to point to a struct.
Helps to avoid hard to debug symptoms, in case we ever try to use
and dereference a drbd_connection or drbd_peer_device
where we in fact don't have any connection at all.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | drivers/block/drbd/drbd_int.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index 297ba406cc2b..a76ceb344d64 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h | |||
@@ -853,7 +853,7 @@ static inline struct drbd_device *minor_to_device(unsigned int minor) | |||
853 | 853 | ||
854 | static inline struct drbd_peer_device *first_peer_device(struct drbd_device *device) | 854 | static inline struct drbd_peer_device *first_peer_device(struct drbd_device *device) |
855 | { | 855 | { |
856 | return list_first_entry(&device->peer_devices, struct drbd_peer_device, peer_devices); | 856 | return list_first_entry_or_null(&device->peer_devices, struct drbd_peer_device, peer_devices); |
857 | } | 857 | } |
858 | 858 | ||
859 | #define for_each_resource(resource, _resources) \ | 859 | #define for_each_resource(resource, _resources) \ |
@@ -2222,7 +2222,7 @@ static inline void drbd_md_flush(struct drbd_device *device) | |||
2222 | 2222 | ||
2223 | static inline struct drbd_connection *first_connection(struct drbd_resource *resource) | 2223 | static inline struct drbd_connection *first_connection(struct drbd_resource *resource) |
2224 | { | 2224 | { |
2225 | return list_first_entry(&resource->connections, | 2225 | return list_first_entry_or_null(&resource->connections, |
2226 | struct drbd_connection, connections); | 2226 | struct drbd_connection, connections); |
2227 | } | 2227 | } |
2228 | 2228 | ||