Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7667EC05027 for ; Thu, 2 Feb 2023 20:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbjBBUXm (ORCPT ); Thu, 2 Feb 2023 15:23:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjBBUXj (ORCPT ); Thu, 2 Feb 2023 15:23:39 -0500 Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9362B6DFFD for ; Thu, 2 Feb 2023 12:23:35 -0800 (PST) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id Ng7FpzaaXkc0dNg7FpPXWm; Thu, 02 Feb 2023 21:23:32 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 02 Feb 2023 21:23:32 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Mustafa Ismail , Shiraz Saleem , Jason Gunthorpe , Leon Romanovsky Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-rdma@vger.kernel.org Subject: [PATCH] RDMA/irdma: Slightly optimize irdma_form_ah_cm_frame() Date: Thu, 2 Feb 2023 21:23:24 +0100 Message-Id: <098e3c397be0436f1867899245ecfe656c472110.1675369386.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no need to zero 'pktsize' bytes of 'buf', only the header needs to be cleared, to be safe. All the other bytes are already written with some memcpy() at the end of the function. Doing so also gives the opportunity to the compiler to avoid the memset() call. It can be inlined now that the length is known as compile time. Signed-off-by: Christophe JAILLET --- Just in case, here is the diff of what is generated by gcc 11.3.0 before and after the patch. .L736: -# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, pktsize); +# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, sizeof(*tcph)); call __sanitizer_cov_trace_pc # - xorl %esi, %esi # - movzwl %r13w, %edx # _194, __fortify_size - movq %rbp, %rdi # buf, - call memset # - leaq 104(%r12), %rax #, _259 + movl $0, 16(%rbp) #, MEM [(void *)buf_114] + leaq 104(%r12), %rax #, _295 +# drivers/infiniband/hw/irdma/cm.c:342: sqbuf->totallen = pktsize; + movzwl %r13w, %r13d # _192, _192 +# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, sizeof(*tcph)); + movq $0, 0(%rbp) #, MEM [(void *)buf_114] +# drivers/infiniband/hw/irdma/cm.c:342: sqbuf->totallen = pktsize; + movq %rax, %rdi # _295, +# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, sizeof(*tcph)); + movq $0, 8(%rbp) #, MEM [(void *)buf_114] + movq %rax, 64(%rsp) # _295, %sfp # drivers/infiniband/hw/irdma/cm.c:342: sqbuf->totallen = pktsize; --- drivers/infiniband/hw/irdma/cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c index 195aa9ea18b6..48c2a303e9ec 100644 --- a/drivers/infiniband/hw/irdma/cm.c +++ b/drivers/infiniband/hw/irdma/cm.c @@ -337,7 +337,7 @@ static struct irdma_puda_buf *irdma_form_ah_cm_frame(struct irdma_cm_node *cm_no pktsize = sizeof(*tcph) + opts_len + hdr_len + pd_len; - memset(buf, 0, pktsize); + memset(buf, 0, sizeof(*tcph)); sqbuf->totallen = pktsize; sqbuf->tcphlen = sizeof(*tcph) + opts_len; -- 2.34.1