From patchwork Mon Jan 13 22:17:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Child X-Patchwork-Id: 13938158 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 192491D54EF; Mon, 13 Jan 2025 22:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806653; cv=none; b=hRVi3FNziv3x8JmsS1Bm0zSQgcDij27c4VKVKkXYd1JGFShgaOom51n2a1bZel+2+YjUSLSvT7efoScUUzEMqHO7+p71dvVTLLZyszUPumCgsmOfRA3f0DkUxEi/8K99VRo+DAddw2tqTPhjHmyvV8+JhUeU7sdXZG/LURBX+Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806653; c=relaxed/simple; bh=RQnhJRNgDLemGSI57q+8mmqZ5dCA8weUN4fT2xuvUC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JmJVltnf3kpBaBkIXdcIc3CWiEsfCM35T4eMUlEEdNXNE0NEIh/19OmjNQadZEjqN3+t9YDhqo9MQMSHoIN79kn+k5i/pYHuYRhPyx5svFeohPHsCGiUG38SNFsEac0ssIxMAXMVd0AVzyqCQVe2uQ9Coqmv2V0wsjQe3/BSzSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=BdQ0piND; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="BdQ0piND" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DE6U2Y019902; Mon, 13 Jan 2025 22:17:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=2wFLw8tFW9H7uxQCP yaGBT9D6W9KrM8Uc9NqUhP/j70=; b=BdQ0piNDbicMDQ5u6y3/KMV5y5IYroA/L y88AR7DSbzAeLDbRJfSPFD1rkRd/afI+qXwwz3NwMh4Th6NMQVmeE17T2MEC/69G tnq7Ztku2dysZZdaJmNZp0pDt8/8enI8m9K5EB48e8WPXOOCtStyz5TCuKXu6JdP Lvr7gwvplbfDMHbkKMVZz6VWVC++E6IyFEL/vjMxUDRDCdEhMPPnmiUtPQJWcNgD t6G8mHQoDfigUZNzBI0e3llAH1PNDEuwHAUhRrikj2S9RSiajDRWqkOgps86HtOm z9ENHe/wBGWe+Aw2Qs8Rn0bNmXCjatTZTqLLux164x+sFkW/2z6/g== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4454a5a2fa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Jan 2025 22:17:30 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50DJOQr2002666; Mon, 13 Jan 2025 22:17:30 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4443by0f7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Jan 2025 22:17:30 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50DMHRbT32572044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 22:17:27 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5942558066; Mon, 13 Jan 2025 22:17:27 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 092AB58055; Mon, 13 Jan 2025 22:17:27 +0000 (GMT) Received: from li-4c4c4544-0047-5210-804b-b8c04f323634.ibm.com.com (unknown [9.61.148.44]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 13 Jan 2025 22:17:26 +0000 (GMT) From: Nick Child To: linux-kernel@vger.kernel.org Cc: nick.child@ibm.com, netdev@vger.kernel.org, Nick Child Subject: [PATCH 1/3] hexdump: Implement macro for converting large buffers Date: Mon, 13 Jan 2025 16:17:19 -0600 Message-ID: <20250113221721.362093-2-nnac123@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113221721.362093-1-nnac123@linux.ibm.com> References: <20250113221721.362093-1-nnac123@linux.ibm.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: c4c-LSmt2tDpjExehFmYl8_-zT5dpUXR X-Proofpoint-ORIG-GUID: c4c-LSmt2tDpjExehFmYl8_-zT5dpUXR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 suspectscore=0 phishscore=0 mlxlogscore=937 spamscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501130173 Define for_each_line_in_hex_dump which loops over a buffer and calls hex_dump_to_buffer for each segment in the buffer. This allows the caller to decide what to do with the resulting string and is not limited by a specific printing format like print_hex_dump. Signed-off-by: Nick Child --- include/linux/printk.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/printk.h b/include/linux/printk.h index 4217a9f412b2..d55968f7ac10 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -755,6 +755,27 @@ enum { extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, char *linebuf, size_t linebuflen, bool ascii); +/** + * for_each_line_in_hex_dump - iterate over buffer, converting into hex ASCII + * @i - offset in @buff + * @rowsize: number of bytes to print per line; must be 16 or 32 + * @linebuf: where to put the converted data + * @linebuflen: total size of @linebuf, including space for terminating NUL + * IOW >= (@rowsize * 2) + ((@rowsize - 1 / @groupsize)) + 1 + * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) + * @buf: data blob to dump + * @len: number of bytes in the @buf + */ + #define for_each_line_in_hex_dump(i, rowsize, linebuf, linebuflen, groupsize, \ + buf, len) \ + for ((i) = 0; \ + (i) < (len) && \ + hex_dump_to_buffer((unsigned char *)(buf) + (i), \ + min((len) - (i), rowsize), \ + (rowsize), (groupsize), (linebuf), \ + (linebuflen), false); \ + (i) += (rowsize) == 16 || (rowsize) == 32 ? (rowsize) : 16 \ + ) #ifdef CONFIG_PRINTK extern void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, From patchwork Mon Jan 13 22:17:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Child X-Patchwork-Id: 13938159 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57E2E1EBFE8; Mon, 13 Jan 2025 22:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806653; cv=none; b=Mf+VhIMvRi34SsFXjfQHo0AXEPWf0IBQ9ZVWiKEX4XvJ1JaLd0hUfSKf6dus4hSgi1VIHHlQaBFumKtMbf6OafXLwigF7SL8knXkCKIs6w3OCzwWSbGSA3zLhBk+B7fpQXndwoKgT2QWDTOPY60Nzxt7JUWWykdBbIKtsQyFXmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806653; c=relaxed/simple; bh=U/1rVWcsrXbc1r4VEwXO/XZRy38DCLOMvGKhemqBFww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EnXH3S0Rj9lkheYi3gNs7r8SRhn3n3rPLBLtLOklB/cBb8SDRL44yLOci73L6jE9foj2LoFbtT9CZ1jfA9rH9ZLYYErUmDrEFi/srRMP7fqSrIlM91gfSO2SN9S7qhx8ys8yXRksioZgNSGM1C1b5aquMQu9iUpfyBjVauKX/iQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ePkIRnvy; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ePkIRnvy" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DGJkor002370; Mon, 13 Jan 2025 22:17:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=peq0z7fMiaJEdZUrk Z7UXf2AGzRX/IAZoNjAPeh6Zc8=; b=ePkIRnvyAqliqqupW6gYaSQJoc3N9DmBx JLT8Fu0D5dRi+70OPctuQogiAfPGpcR/LWr5oymwbnrU5MxmY5AT1L3UwlMsy/L4 bphPob2E8Na4JRzRn7NA7Mg9sAN0IAJObPM4prAWjoXVz0KnCFltfsBOT6iDF1yV kweS6bsuj8i4VbyFQW2EVEgbErw0gntFFh2439mqQ5pwi8iEHeBSxV0d9OucZQtR /fH/BtPhZeFc6oXN/MclHuIBmXTe2++KeT+ts+VKLhys3T8+D9m4iznLFSJyjk8A Bvw79ehxdE4Wkwhx3JBxZaY4FpR51FN/Ab4++yW4osGYhzzEG8PIw== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 444uagvdgc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Jan 2025 22:17:31 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50DL5YWP000827; Mon, 13 Jan 2025 22:17:30 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 44456jr3by-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Jan 2025 22:17:30 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50DMHR6P32572046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 22:17:28 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C4C185804B; Mon, 13 Jan 2025 22:17:27 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F51158055; Mon, 13 Jan 2025 22:17:27 +0000 (GMT) Received: from li-4c4c4544-0047-5210-804b-b8c04f323634.ibm.com.com (unknown [9.61.148.44]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 13 Jan 2025 22:17:27 +0000 (GMT) From: Nick Child To: linux-kernel@vger.kernel.org Cc: nick.child@ibm.com, netdev@vger.kernel.org, Nick Child Subject: [PATCH 2/3] hexdump: Use for_each macro in print_hex_dump Date: Mon, 13 Jan 2025 16:17:20 -0600 Message-ID: <20250113221721.362093-3-nnac123@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113221721.362093-1-nnac123@linux.ibm.com> References: <20250113221721.362093-1-nnac123@linux.ibm.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: nn5yBUDGchBH99OhndwOV3rscTWIsNcI X-Proofpoint-GUID: nn5yBUDGchBH99OhndwOV3rscTWIsNcI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=804 malwarescore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 spamscore=0 mlxscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501130173 The looping logic in print_hex_dump can be handled by the macro for_each_line_in_hex_dump. Signed-off-by: Nick Child --- lib/hexdump.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/hexdump.c b/lib/hexdump.c index c3db7c3a7643..181b82dfe40d 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -263,19 +263,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, const void *buf, size_t len, bool ascii) { const u8 *ptr = buf; - int i, linelen, remaining = len; + int i; unsigned char linebuf[32 * 3 + 2 + 32 + 1]; if (rowsize != 16 && rowsize != 32) rowsize = 16; - for (i = 0; i < len; i += rowsize) { - linelen = min(remaining, rowsize); - remaining -= rowsize; - - hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, - linebuf, sizeof(linebuf), ascii); - + for_each_line_in_hex_dump(i, rowsize, linebuf, sizeof(linebuf), + groupsize, buf, len) { switch (prefix_type) { case DUMP_PREFIX_ADDRESS: printk("%s%s%p: %s\n", From patchwork Mon Jan 13 22:17:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Child X-Patchwork-Id: 13938161 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0DB11EE7B0; Mon, 13 Jan 2025 22:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806655; cv=none; b=HQ0m7Axsc3/DW4IwKUjaCVmKfQfjrb8iOnq797yxAudIU/s9rSVJHXc4Qe4n8ItWZ93MUoNmm1nIXfyMj7cZnJ88PrNIe7I+PMBkdgrYkP+0aP4/1kfpEgs4ezk2DrxnBGCrMp8DJqXgZzT/ax/GXf4Qgd2C2CN+L0K0/iuIqLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806655; c=relaxed/simple; bh=IW2V5eMxUjMuGbD59gBqxYAMjzcD5HGkFFt13PdLcGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pPaBTzKhBz7uSW+JkrjvkLkSyHg79wlSZNF/KHnffdicHqxu5dKEJZ1/W2a90fGA4V1WFXeG0eT0YmDkOQ5GTUCLyD7qfefMTof+M1rvGyhVnCE3ZasJMD44r7rOUwrF8chzRY35cWUZUtdg4YwG1pQxeQ2v7CVl8KupaKOqCaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=JG9Wb8Kw; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="JG9Wb8Kw" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DFfelR002372; Mon, 13 Jan 2025 22:17:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ucRLBcOE+YQ9Qwwpt C6XtxG02p46d6+s0y1G8OqLQB8=; b=JG9Wb8KwqbagCW4f9IMnfzmxFnWsuI4Xz HTQN+psMe22Dhk/4dDGel4gVVnuDE/k6PG50I7ND3bbQPN3EgVihMoLMN1rmK14w 5wD3fp7Lf5qMwk6PHB8FhM9XvPLKAtlyv9cpGNPbwnbnykgEvpfidu27EPE2S6O9 voHQYvvK/vjPvvNYH8VTYh93CgnMwiF8iWd7F+EdteJDdc+HKijTvuJNvA7N1xjO a11S9jy3rNBV8SGu5IoDsCpxOLrWz3M8OWDgElfDc+VW5GRrYXtCNArtqLwlI7v1 5+TGTdEaaMdXz8l3m4dCbRdx0r4g9a17tyvFqnvlJr9ND3M5RGuyg== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 444uagvdgg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Jan 2025 22:17:32 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50DK07t0002663; Mon, 13 Jan 2025 22:17:31 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4443by0f7n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Jan 2025 22:17:31 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50DMHSaK6357630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 22:17:29 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C11EE58059; Mon, 13 Jan 2025 22:17:28 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C2E25804B; Mon, 13 Jan 2025 22:17:28 +0000 (GMT) Received: from li-4c4c4544-0047-5210-804b-b8c04f323634.ibm.com.com (unknown [9.61.148.44]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 13 Jan 2025 22:17:28 +0000 (GMT) From: Nick Child To: linux-kernel@vger.kernel.org Cc: nick.child@ibm.com, netdev@vger.kernel.org, Nick Child Subject: [PATCH 3/3] ibmvnic: Print data buffers with kernel API's Date: Mon, 13 Jan 2025 16:17:21 -0600 Message-ID: <20250113221721.362093-4-nnac123@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113221721.362093-1-nnac123@linux.ibm.com> References: <20250113221721.362093-1-nnac123@linux.ibm.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: BsLVXfW1L6gUnsUfERQBcs_A1BVRAj0j X-Proofpoint-GUID: BsLVXfW1L6gUnsUfERQBcs_A1BVRAj0j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=830 malwarescore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 spamscore=0 mlxscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501130173 X-Patchwork-Delegate: kuba@kernel.org Previously, data buffers that were to be printed were cast to 8 byte integers and printed. This can lead to buffer overflow if the length of the buffer is not a multiple of 8. Simplify and safeguard printing by using kernel provided functions to print these data blobs. Signed-off-by: Nick Child Reviewed-by: Jacob Keller --- drivers/net/ethernet/ibm/ibmvnic.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index e95ae0d39948..a8f1feb9a2e7 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -4834,6 +4834,7 @@ static int send_login(struct ibmvnic_adapter *adapter) struct device *dev = &adapter->vdev->dev; struct vnic_login_client_data *vlcd; dma_addr_t rsp_buffer_token; + unsigned char hex_str[16 * 3]; dma_addr_t buffer_token; size_t rsp_buffer_size; union ibmvnic_crq crq; @@ -4937,9 +4938,9 @@ static int send_login(struct ibmvnic_adapter *adapter) vnic_add_client_data(adapter, vlcd); netdev_dbg(adapter->netdev, "Login Buffer:\n"); - for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) { - netdev_dbg(adapter->netdev, "%016lx\n", - ((unsigned long *)(adapter->login_buf))[i]); + for_each_line_in_hex_dump(i, 16, hex_str, sizeof(hex_str), 8, + adapter->login_buf, adapter->login_buf_sz) { + netdev_dbg(adapter->netdev, "%s\n", hex_str); } memset(&crq, 0, sizeof(crq)); @@ -5317,15 +5318,17 @@ static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter) { struct device *dev = &adapter->vdev->dev; struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; + unsigned char hex_str[16 * 3]; int i; dma_unmap_single(dev, adapter->ip_offload_tok, sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE); netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n"); - for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++) - netdev_dbg(adapter->netdev, "%016lx\n", - ((unsigned long *)(buf))[i]); + for_each_line_in_hex_dump(i, 16, hex_str, sizeof(hex_str), 8, buf, + sizeof(adapter->ip_offload_buf)) { + netdev_dbg(adapter->netdev, "%s\n", hex_str); + } netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum); netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum); @@ -5518,6 +5521,7 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, struct net_device *netdev = adapter->netdev; struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf; struct ibmvnic_login_buffer *login = adapter->login_buf; + unsigned char hex_str[16 * 3]; u64 *tx_handle_array; u64 *rx_handle_array; int num_tx_pools; @@ -5556,9 +5560,10 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, netdev->mtu = adapter->req_mtu - ETH_HLEN; netdev_dbg(adapter->netdev, "Login Response Buffer:\n"); - for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) { - netdev_dbg(adapter->netdev, "%016lx\n", - ((unsigned long *)(adapter->login_rsp_buf))[i]); + for_each_line_in_hex_dump(i, 16, hex_str, sizeof(hex_str), 8, + adapter->login_rsp_buf, + adapter->login_rsp_buf_sz) { + netdev_dbg(adapter->netdev, "%s\n", hex_str); } /* Sanity checks */