Skip to content

Commit 234041d

Browse files
committed
sgi-xp: Use designated initializers
Prepare to mark sensitive kernel structures for randomization by making sure they're using designated initializers. In this case, no initializers are needed (they can be NULL initialized and callers adjusted to check for NULL, which is more efficient than an indirect call). Cc: Robin Holt <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 7585d12 commit 234041d

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

drivers/misc/sgi-xp/xp.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ static inline enum xp_retval
309309
xpc_send(short partid, int ch_number, u32 flags, void *payload,
310310
u16 payload_size)
311311
{
312+
if (!xpc_interface.send)
313+
return xpNotLoaded;
314+
312315
return xpc_interface.send(partid, ch_number, flags, payload,
313316
payload_size);
314317
}
@@ -317,19 +320,26 @@ static inline enum xp_retval
317320
xpc_send_notify(short partid, int ch_number, u32 flags, void *payload,
318321
u16 payload_size, xpc_notify_func func, void *key)
319322
{
323+
if (!xpc_interface.send_notify)
324+
return xpNotLoaded;
325+
320326
return xpc_interface.send_notify(partid, ch_number, flags, payload,
321327
payload_size, func, key);
322328
}
323329

324330
static inline void
325331
xpc_received(short partid, int ch_number, void *payload)
326332
{
327-
return xpc_interface.received(partid, ch_number, payload);
333+
if (xpc_interface.received)
334+
xpc_interface.received(partid, ch_number, payload);
328335
}
329336

330337
static inline enum xp_retval
331338
xpc_partid_to_nasids(short partid, void *nasids)
332339
{
340+
if (!xpc_interface.partid_to_nasids)
341+
return xpNotLoaded;
342+
333343
return xpc_interface.partid_to_nasids(partid, nasids);
334344
}
335345

drivers/misc/sgi-xp/xp_main.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,9 @@ struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
6969
EXPORT_SYMBOL_GPL(xpc_registrations);
7070

7171
/*
72-
* Initialize the XPC interface to indicate that XPC isn't loaded.
72+
* Initialize the XPC interface to NULL to indicate that XPC isn't loaded.
7373
*/
74-
static enum xp_retval
75-
xpc_notloaded(void)
76-
{
77-
return xpNotLoaded;
78-
}
79-
80-
struct xpc_interface xpc_interface = {
81-
(void (*)(int))xpc_notloaded,
82-
(void (*)(int))xpc_notloaded,
83-
(enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
84-
(enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
85-
void *))xpc_notloaded,
86-
(void (*)(short, int, void *))xpc_notloaded,
87-
(enum xp_retval(*)(short, void *))xpc_notloaded
88-
};
74+
struct xpc_interface xpc_interface = { };
8975
EXPORT_SYMBOL_GPL(xpc_interface);
9076

9177
/*
@@ -115,17 +101,7 @@ EXPORT_SYMBOL_GPL(xpc_set_interface);
115101
void
116102
xpc_clear_interface(void)
117103
{
118-
xpc_interface.connect = (void (*)(int))xpc_notloaded;
119-
xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
120-
xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16))
121-
xpc_notloaded;
122-
xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *,
123-
u16, xpc_notify_func,
124-
void *))xpc_notloaded;
125-
xpc_interface.received = (void (*)(short, int, void *))
126-
xpc_notloaded;
127-
xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *))
128-
xpc_notloaded;
104+
memset(&xpc_interface, 0, sizeof(xpc_interface));
129105
}
130106
EXPORT_SYMBOL_GPL(xpc_clear_interface);
131107

@@ -188,7 +164,8 @@ xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
188164

189165
mutex_unlock(&registration->mutex);
190166

191-
xpc_interface.connect(ch_number);
167+
if (xpc_interface.connect)
168+
xpc_interface.connect(ch_number);
192169

193170
return xpSuccess;
194171
}
@@ -237,7 +214,8 @@ xpc_disconnect(int ch_number)
237214
registration->assigned_limit = 0;
238215
registration->idle_limit = 0;
239216

240-
xpc_interface.disconnect(ch_number);
217+
if (xpc_interface.disconnect)
218+
xpc_interface.disconnect(ch_number);
241219

242220
mutex_unlock(&registration->mutex);
243221

0 commit comments

Comments
 (0)