Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <andy.shevchenko@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Message-Id: <20191011155036.36748-1-andriy.shevchenko@linux.intel.com>
Signed-off-by: Corey Minyard <cminyard@mvista.com>

authored by

Andy Shevchenko and committed by
Corey Minyard
8ee7b485 cbb79863

+4 -23
+4 -23
drivers/char/ipmi/ipmi_msghandler.c
··· 44 44 static int handle_one_recv_msg(struct ipmi_smi *intf, 45 45 struct ipmi_smi_msg *msg); 46 46 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 - 66 47 static bool initialized; 67 48 static bool drvregistered; 68 49 ··· 2256 2275 ipmi_free_smi_msg(smi_msg); 2257 2276 ipmi_free_recv_msg(recv_msg); 2258 2277 } else { 2259 - ipmi_debug_msg("Send", smi_msg->data, smi_msg->data_size); 2278 + pr_debug("Send: %*ph\n", smi_msg->data_size, smi_msg->data); 2260 2279 2261 2280 smi_send(intf, intf->handlers, smi_msg, priority); 2262 2281 } ··· 3720 3739 msg->data[10] = ipmb_checksum(&msg->data[6], 4); 3721 3740 msg->data_size = 11; 3722 3741 3723 - ipmi_debug_msg("Invalid command:", msg->data, msg->data_size); 3742 + pr_debug("Invalid command: %*ph\n", msg->data_size, msg->data); 3724 3743 3725 3744 rcu_read_lock(); 3726 3745 if (!intf->in_shutdown) { ··· 4207 4226 int requeue; 4208 4227 int chan; 4209 4228 4210 - ipmi_debug_msg("Recv:", msg->rsp, msg->rsp_size); 4229 + pr_debug("Recv: %*ph\n", msg->rsp_size, msg->rsp); 4211 4230 4212 4231 if ((msg->data_size >= 2) 4213 4232 && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) ··· 4566 4585 smi_msg->data_size = recv_msg->msg.data_len; 4567 4586 smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid); 4568 4587 4569 - ipmi_debug_msg("Resend: ", smi_msg->data, smi_msg->data_size); 4588 + pr_debug("Resend: %*ph\n", smi_msg->data_size, smi_msg->data); 4570 4589 4571 4590 return smi_msg; 4572 4591 }