Skip to content

Commit 8ee7b48

Browse files
andy-shevcminyard
authored andcommitted
ipmi: use %*ph to print small buffer
Use %*ph format to print small buffer as hex string. The change is safe since the specifier can handle up to 64 bytes and taking into account the buffer size of 100 bytes on stack the function has never been used to dump more than 32 bytes. Note, this also avoids potential buffer overflow if the length of the input buffer is bigger. This completely eliminates ipmi_debug_msg() in favour of Dynamic Debug. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Message-Id: <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent cbb7986 commit 8ee7b48

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,6 @@ static void need_waiter(struct ipmi_smi *intf);
4444
static int handle_one_recv_msg(struct ipmi_smi *intf,
4545
struct ipmi_smi_msg *msg);
4646

47-
#ifdef DEBUG
48-
static void ipmi_debug_msg(const char *title, unsigned char *data,
49-
unsigned int len)
50-
{
51-
int i, pos;
52-
char buf[100];
53-
54-
pos = snprintf(buf, sizeof(buf), "%s: ", title);
55-
for (i = 0; i < len; i++)
56-
pos += snprintf(buf + pos, sizeof(buf) - pos,
57-
" %2.2x", data[i]);
58-
pr_debug("%s\n", buf);
59-
}
60-
#else
61-
static void ipmi_debug_msg(const char *title, unsigned char *data,
62-
unsigned int len)
63-
{ }
64-
#endif
65-
6647
static bool initialized;
6748
static bool drvregistered;
6849

@@ -2275,7 +2256,7 @@ static int i_ipmi_request(struct ipmi_user *user,
22752256
ipmi_free_smi_msg(smi_msg);
22762257
ipmi_free_recv_msg(recv_msg);
22772258
} else {
2278-
ipmi_debug_msg("Send", smi_msg->data, smi_msg->data_size);
2259+
pr_debug("Send: %*ph\n", smi_msg->data_size, smi_msg->data);
22792260

22802261
smi_send(intf, intf->handlers, smi_msg, priority);
22812262
}
@@ -3739,7 +3720,7 @@ static int handle_ipmb_get_msg_cmd(struct ipmi_smi *intf,
37393720
msg->data[10] = ipmb_checksum(&msg->data[6], 4);
37403721
msg->data_size = 11;
37413722

3742-
ipmi_debug_msg("Invalid command:", msg->data, msg->data_size);
3723+
pr_debug("Invalid command: %*ph\n", msg->data_size, msg->data);
37433724

37443725
rcu_read_lock();
37453726
if (!intf->in_shutdown) {
@@ -4226,7 +4207,7 @@ static int handle_one_recv_msg(struct ipmi_smi *intf,
42264207
int requeue;
42274208
int chan;
42284209

4229-
ipmi_debug_msg("Recv:", msg->rsp, msg->rsp_size);
4210+
pr_debug("Recv: %*ph\n", msg->rsp_size, msg->rsp);
42304211

42314212
if ((msg->data_size >= 2)
42324213
&& (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
@@ -4585,7 +4566,7 @@ smi_from_recv_msg(struct ipmi_smi *intf, struct ipmi_recv_msg *recv_msg,
45854566
smi_msg->data_size = recv_msg->msg.data_len;
45864567
smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid);
45874568

4588-
ipmi_debug_msg("Resend: ", smi_msg->data, smi_msg->data_size);
4569+
pr_debug("Resend: %*ph\n", smi_msg->data_size, smi_msg->data);
45894570

45904571
return smi_msg;
45914572
}

0 commit comments

Comments
 (0)