Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2205371pxb; Thu, 28 Oct 2021 18:51:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPSK5Bp5+QSLiYRQfEp6xFmvJes2vFeWfEUnFcNOsQYbLfmCMlrxoEa/sEPXWAzpZ33OfW X-Received: by 2002:a63:bf4a:: with SMTP id i10mr6040484pgo.196.1635472296031; Thu, 28 Oct 2021 18:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635472296; cv=none; d=google.com; s=arc-20160816; b=MdTYiQjYQeYv5fqAY9G0V6SQMuW7kJ3mg+C/KBS5KK8k2J4t/e2XFzaMTFFpSrI2ZG BN4fvYVhct0Gm3LCDdt2U1QIlyc5ivsD2t3TCcO13RN4oEETjfdLPNDNGd/Mciq0RlPT 9ZA3ys5YHb0aOTglZUCHcpWWNmt7lbmZnDtwrb/bzUPR0cGFi80XR38Kosw78yz+BKuH FpyE9Rx3A6ggeMdJqEW3lBSA3NAyprW9w39iAfD796OiYZD3DNtMMsI3VBxWXAZ+xFYy kXwIMuHP7CfyTIm5CTYDwVl3GkYiT8aLaUy7FlPyvDYnNz5dxk9AQg6iTkRi4UI1AJIs K9qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=OqyWyu1hB8XDChT+NEBPXYvPC2qR387OJGM7i8zVSKs=; b=oI2OlNHPTpiS7a2jz0xNRFaainRxgXh9wyaqrBLNnqYx0xR49n3sbE6oAzdTU3dNbb 32T/wgs8ZW5FGPRmKSobRtsFCF+mV++WB0VOM3J/Eeq6GQOVWPnBIs8EMyhIIeCVkh4v arkcBfN7McXjYUFCNF+MkSwSM1NjnaGyuG05J/6BhQni+kmDiT897U8axjdHNTWl27zz 7C//YIdsrnOX9JHyLsdxTWf2wRQZLDJB+G9kzAktGiF7uekbPJ8wcHtgEl0BxB1Pa55N DlrpzyI+zbhK0HbBox0jI2dodmdScBnRwhGGbPuLhxALBrnLvD64r917D7QsLFX483Qf bXZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v70si4744544pgd.286.2021.10.28.18.51.22; Thu, 28 Oct 2021 18:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231436AbhJ2Bvj (ORCPT + 99 others); Thu, 28 Oct 2021 21:51:39 -0400 Received: from smtp25.cstnet.cn ([159.226.251.25]:54066 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229950AbhJ2Bvf (ORCPT ); Thu, 28 Oct 2021 21:51:35 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-05 (Coremail) with SMTP id zQCowAAHyPT_UnthcoKTBQ--.39964S2; Fri, 29 Oct 2021 09:48:47 +0800 (CST) From: Jiasheng Jiang To: andraprs@amazon.com, lexnv@amazon.com, alcioa@amazon.com Cc: linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] nitro_enclaves: Fix implicit type conversion Date: Fri, 29 Oct 2021 01:48:46 +0000 Message-Id: <1635472126-1822073-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: zQCowAAHyPT_UnthcoKTBQ--.39964S2 X-Coremail-Antispam: 1UD129KBjvJXoWxGw1kGF4rXFWxAr1fCw4UArb_yoW5Xr4xpF 4Yq34UJrW8AasrZayxAr17uF15ZF9xW3y7J3y3Cay8Cry5AFy8ZFWDK3sxJr1UCrWkZFy2 y345tw1qgF45C3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkC14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK 6w4l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5kucDU UUU X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variable 'cpu' and 'cpu_sibling' are defined as unsigned int. However in the for_each_cpu, their values are assigned to -1. That doesn't make sense and in the cpumask_next() they are implicitly type conversed to int. It is universally accepted that the implicit type conversion is terrible. Also, having the good programming custom will set an example for others. Thus, it might be better to change the definition of 'cpu' and 'cpu_sibling' from unsigned int to int. Signed-off-by: Jiasheng Jiang --- drivers/virt/nitro_enclaves/ne_misc_dev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c index e21e1e8..2d80879 100644 --- a/drivers/virt/nitro_enclaves/ne_misc_dev.c +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c @@ -168,9 +168,9 @@ static bool ne_check_enclaves_created(void) static int ne_setup_cpu_pool(const char *ne_cpu_list) { int core_id = -1; - unsigned int cpu = 0; + int cpu = 0; cpumask_var_t cpu_pool; - unsigned int cpu_sibling = 0; + int cpu_sibling = 0; unsigned int i = 0; int numa_node = -1; int rc = -EINVAL; @@ -374,7 +374,7 @@ static int ne_setup_cpu_pool(const char *ne_cpu_list) */ static void ne_teardown_cpu_pool(void) { - unsigned int cpu = 0; + int cpu = 0; unsigned int i = 0; int rc = -EINVAL; @@ -516,7 +516,7 @@ static int ne_get_unused_core_from_cpu_pool(void) static int ne_set_enclave_threads_per_core(struct ne_enclave *ne_enclave, int core_id, u32 vcpu_id) { - unsigned int cpu = 0; + int cpu = 0; if (core_id < 0 && vcpu_id == 0) { dev_err_ratelimited(ne_misc_dev.this_device, @@ -562,7 +562,7 @@ static int ne_set_enclave_threads_per_core(struct ne_enclave *ne_enclave, static int ne_get_cpu_from_cpu_pool(struct ne_enclave *ne_enclave, u32 *vcpu_id) { int core_id = -1; - unsigned int cpu = 0; + int cpu = 0; unsigned int i = 0; int rc = -EINVAL; @@ -1017,7 +1017,7 @@ static int ne_start_enclave_ioctl(struct ne_enclave *ne_enclave, struct ne_enclave_start_info *enclave_start_info) { struct ne_pci_dev_cmd_reply cmd_reply = {}; - unsigned int cpu = 0; + int cpu = 0; struct enclave_start_req enclave_start_req = {}; unsigned int i = 0; struct pci_dev *pdev = ne_devs.ne_pci_dev->pdev; @@ -1360,7 +1360,7 @@ static void ne_enclave_remove_all_mem_region_entries(struct ne_enclave *ne_encla */ static void ne_enclave_remove_all_vcpu_id_entries(struct ne_enclave *ne_enclave) { - unsigned int cpu = 0; + int cpu = 0; unsigned int i = 0; mutex_lock(&ne_cpu_pool.mutex); -- 2.7.4