I am trying to print the following variables in my custom Linux Kernel Module for debugging purposes:
__le16 length; // The length of the data
u8 data[128];
The data
variable has a maximum length of 128 bytes but we might not use all if it. The length variable determines how much we used of the data
variable. I want to print the content of data
variable in Hex format. I am doing so using a for loop however, the following code prints each byte in a separate line when I inspect the logs using dmesg
. I suppose this is because of the mechanism of how printk
works. I can still print the content in the same line but as string using %s
. However, I want to print all the bytes in the same line in Hex format. How can I do that?
u8 i = 0;
for (i = 0 ; i < length ; i++)
{
printk("0x%02x ", data[i]);
}
printk("\n");