Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1169098rdd; Wed, 10 Jan 2024 10:38:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgTbozp/yVW0FNTFoqK2fi/OJ2K8k8YDg8Ih0IhAKThL8xPmRqbI4rlv0DVTKVDw72WIeO X-Received: by 2002:a17:902:ab96:b0:1d5:4c72:3e61 with SMTP id f22-20020a170902ab9600b001d54c723e61mr961746plr.94.1704911880095; Wed, 10 Jan 2024 10:38:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704911880; cv=none; d=google.com; s=arc-20160816; b=HxenqVABaCTSzKtYk1xfZd9rZO8CKe4RFcX3NUEEugeWsdhb7dCwyNWoQnKbFjMf/2 Ozzur28wpqT7TeHAPMu02HwwDNdi/sgzv9R6xGy+BIlJp/KJWAxMeKnA9i6tPq7crp+7 eh0yVIOlIuR7XqFoHFRHYLGxgbU3M0cgu+hxsPeTqJddCZLzM9i6NQB/SEbzsAV60yNQ Ts+8Fr4Qb4pNPStmCgg/qejaW6hGRK+ZGYViamZqRFbB2Fpd1FvKY3FT3JXp0La4dD1T iQXheNWm4uzD6Vx19AD5Acas0+qSIo2YEZuxOywXpgbAi37B0L1eVEunnTXIS2aoHQ4Y lVkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=0bRmYP/rNPWw+8+5BllGhXOmL25I0DLXSeKEgWDNQLs=; fh=dijaVeffAqAyRqDxMo3pEXiNUISedIzDYq/T/0M93jE=; b=ztfUNuqP2PzJXgclq/e59DbSMoRXqNg2o2LvEjNAwLTKeF70wnNvtl86bYM+H8iAk6 gedQbIZXk06t1m0WhPFvqfFqwNToJRKLWrDus1jfH+x+mDSuWhvEg2NhVpAc2dldeJTq eSgxmvnsP36NKBJ1i17XFyecz4PwOEP3nEjM3/Fu/Szz51Tc7hu93MM4IUx+L/jyFHYN cNUPa2h0suGK+Du8PHU5KnTenyAqPrMkmxnXxKaCkp/wEYAk1HWf+bo/Ck4JiWtDEZmO 8kjUUX1sREJC0LQRbaqwSHo/lMP1PRxM0L9IloFk93CJK9oz6NxhlKZxhy/9YKYj/U8x kPWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B4y9m4px; spf=pass (google.com: domain of linux-kernel+bounces-22606-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c12-20020a170903234c00b001d556872df5si4067837plh.335.2024.01.10.10.37.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 10:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22606-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B4y9m4px; spf=pass (google.com: domain of linux-kernel+bounces-22606-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 514E9B25E1E for ; Wed, 10 Jan 2024 18:37:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B4164D58D; Wed, 10 Jan 2024 18:37:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="B4y9m4px" Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D350E4D582 for ; Wed, 10 Jan 2024 18:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40d87df95ddso46234605e9.0 for ; Wed, 10 Jan 2024 10:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704911866; x=1705516666; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0bRmYP/rNPWw+8+5BllGhXOmL25I0DLXSeKEgWDNQLs=; b=B4y9m4pxhpxRGOujWf+e9E3fjzFu5dOFOwf6HawGfDo4SP73owmvHqGT6+ep0hBuY4 RhU2Ca7MzBDbCnCSE0A47ldGPGAuyW6Y1qnIecRaj3u43zkfAJWb0ab9G8E52rw//fjV xg8dYajX+RjVoFVP9Lbpk3hT85MqmDH4e/BzkXUjcT45ZHgtVkHlR0If7NLkvwkZVr24 K4Cd6BxoKiQyanYjNYrHvcnOeUFowoUl0JOyRNQqpKhZ+1TOfmVGQtbZibTsjkViDfzi hJQRObKO+yDpY88g+6Wz6rmYy3NDFY7IgKHiieRrWGZLomxHaSza63XMzBJ0AOONSoF1 szBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704911866; x=1705516666; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0bRmYP/rNPWw+8+5BllGhXOmL25I0DLXSeKEgWDNQLs=; b=cUihJlPasx0EouyPPwKmtQS0jBQlCXAIHmBESQAtAjdNqOoYxJZXU5CSurPbZg733b kmHpPD4EdJLS7rdxqd7lX0rDQ/zvks33xTuNlRMiCdUGUdiOOx4DT2UKBItuBXPzUCZl pAY8ds4+GmzmY4tB008HtC1a9k5hWwwp0yTn8V6DmiHcQv8MuNvBxRNdMkESumIA/E8L gjl8m0QvPvXXkkdRFlROmk06QleTd9ktmyq+nRqyzJsFtg5f+qXj/r3G57zCMIZ2Gu9p +jtxfFK6BepZBEmN1s33aR/oRZSQHOCDik3T1l2H2jLk7qPhexq/QEENN0F3HjqlPiGF 2NIA== X-Gm-Message-State: AOJu0Yww5yIl+VSybgWuPZo59c35BHiHim6RjreohoFwpylugZQityMM sYBl005SD0DDvPQl6W7t49NAo0pTBvT55w== X-Received: by 2002:a05:600c:1603:b0:40e:54f1:5d3e with SMTP id m3-20020a05600c160300b0040e54f15d3emr372091wmn.199.1704911866001; Wed, 10 Jan 2024 10:37:46 -0800 (PST) Received: from localhost ([102.140.209.237]) by smtp.gmail.com with ESMTPSA id bg3-20020a05600c3c8300b0040d91fa270fsm3064239wmb.36.2024.01.10.10.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 10:37:45 -0800 (PST) Date: Wed, 10 Jan 2024 21:37:42 +0300 From: Dan Carpenter To: Michael Kelley Cc: Markus Elfring , "linux-hyperv@vger.kernel.org" , "kernel-janitors@vger.kernel.org" , Dexuan Cui , Haiyang Zhang , "K. Y. Srinivasan" , Wei Liu , "cocci@inria.fr" , LKML Subject: Re: Drivers: hv: vmbus: One function call less in create_gpadl_header() after error detection Message-ID: References: <6d97cafb-ad7c-41c1-9f20-41024bb18515@web.de> <82054a0a-72e5-45b2-8808-e411a9587406@web.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: The second half of the if statement is basically duplicated. It doesn't need to be treated as a special case. We could do something like below. I deliberately didn't delete the tabs. Also I haven't tested it. regards, dan carpenter diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 56f7e06c673e..2ba65f9ad3f1 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -328,9 +328,9 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer, sizeof(struct gpa_range); pfncount = pfnsize / sizeof(u64); - if (pagecount > pfncount) { - /* we need a gpadl body */ - /* fill in the header */ + if (pagecount < pfncount) + pfncount = pagecount; + msgsize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pfncount * sizeof(u64); @@ -410,31 +410,6 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer, pfnsum += pfncurr; pfnleft -= pfncurr; } - } else { - /* everything fits in a header */ - msgsize = sizeof(struct vmbus_channel_msginfo) + - sizeof(struct vmbus_channel_gpadl_header) + - sizeof(struct gpa_range) + pagecount * sizeof(u64); - msgheader = kzalloc(msgsize, GFP_KERNEL); - if (msgheader == NULL) - goto nomem; - - INIT_LIST_HEAD(&msgheader->submsglist); - msgheader->msgsize = msgsize; - - gpadl_header = (struct vmbus_channel_gpadl_header *) - msgheader->msg; - gpadl_header->rangecount = 1; - gpadl_header->range_buflen = sizeof(struct gpa_range) + - pagecount * sizeof(u64); - gpadl_header->range[0].byte_offset = 0; - gpadl_header->range[0].byte_count = hv_gpadl_size(type, size); - for (i = 0; i < pagecount; i++) - gpadl_header->range[0].pfn_array[i] = hv_gpadl_hvpfn( - type, kbuffer, size, send_offset, i); - - *msginfo = msgheader; - } return 0; nomem: