Message ID | 20240119094948.275390-1-chentao@kylinos.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-30979-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp900720dyb; Fri, 19 Jan 2024 01:53:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGV87PqB0wWPcEza5Wq1Vq1Pzg1g6z/fvGBNZwOgDOdp8auajeqqOQYlUp0WxaafZx4Ccrj X-Received: by 2002:a17:906:3a88:b0:a28:716d:8db9 with SMTP id y8-20020a1709063a8800b00a28716d8db9mr1272615ejd.21.1705658010479; Fri, 19 Jan 2024 01:53:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705658010; cv=pass; d=google.com; s=arc-20160816; b=jsxzH4Jr16ZznmWQKQRtLz6MQnS2cunm4oHCF5hVYaoQvEr/LAVsCViYgZq8Oqd5WV cnOmzH6rM/ofOTREYpWLYMCWwbChqiS+KwhMg09EP2Li4k4+U6kU8p7BddHtYuWFkrGY vhkqY2gaU7+PXLCZyUqjWSK5RcOLwkgaw7zwM4m6/kLa+URcGuR/SwYCvnCdC/3t7N8z z2Xcm9oEIAe4sR24xoLVMMcqABjoWCFTjPOSQ1x007HtTPdL/Ku6kV2xZ2+UZaFFyYcQ xlq8A++RMtdMGc+V0961vhAU72Cn4znSFp2+KP3QtQvKPYMCD/z/i0A/pPHil7n7gvok EKlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=wntJ4WE/g/dhvPgbuny9TJkaxTtQtgBtgysqLPbyD/0=; fh=goHxNByvwQVo7z329X1K7nVZ18OiJSFpatWQWDOPZNg=; b=z296Ta5XCZeZ3esG9nElrDudzMmZSSeS2rfp0/lrzW8e0tVw2Xg7fGorLFKNwXyOuF SEhNfoL9wWs/4OpwvyQXxL4z/HjlxU51fiH9NqHxyH2zZlwuWKraB1eqVHvyC4lfYS+v RP8voV43rBpWYpI4YbuX0JH5A9Rw+7Aoocg7DU6cO7St5DcebI2teVQ+MoeVgwMRRJGS dvG1gwkBQvyhMuUpVp6DfdOYva1aOBARR0OuzS/qsx9fF2SY5HZyJIIhtjRDrrNHHWto u7U1oVyYIdIJR7ZuF8aqXYKvqUJFgBnDDckertaz+NTdyAl/l7WB6Vyu55/Z1FMyn4+a YKWg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-30979-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30979-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h24-20020a170906591800b00a2f880155absi258803ejq.633.2024.01.19.01.53.30 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 01:53:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30979-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-30979-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30979-ouuuleilei=gmail.com@vger.kernel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1DBD31F236E2 for <ouuuleilei@gmail.com>; Fri, 19 Jan 2024 09:53:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D113F3C47A; Fri, 19 Jan 2024 09:50:17 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 F41463DBA6 for <linux-kernel@vger.kernel.org>; Fri, 19 Jan 2024 09:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705657816; cv=none; b=RdUK5onNAItf9k18ciem078CAmeMqjAshmD1m8EgxL1RkfXCABvE/M7Uwvh2njNxArZzmRHeiSxk2b7VxTbrquEPL11kuH7P4EdDVwMX8hXm1FkzxUDgPsidMh/ggVuG0s8JjRG4cncRzFNBH5yXQjsP0IA0hzMKJO17D9owj7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705657816; c=relaxed/simple; bh=+jYeff6P/rbIvUd5Pi2gz9/ppXxP7MMc7hyFsqL1Pko=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DI+MXhHRCjY2Q8cuWPpseNhFSwxEXBQN2LfoEXrl+7L4iWXUMLL7GNmjcCB+QqgYKvXdoSVyaify/hvxFzisOk6SX2OxDm80G8ehLwC98D4w12YBurFAHjyiXYUk414zznrATckLm4t8Ls4GN2/qBJq3L2qUW1RPH81WGmQFgiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 32f247eb48334c838525b049013cc8ba-20240119 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:c3c69ea8-3676-47d9-80e3-92e8fc4c3fcf,IP:10, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:-3,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-18 X-CID-INFO: VERSION:1.1.35,REQID:c3c69ea8-3676-47d9-80e3-92e8fc4c3fcf,IP:10,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:-3,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-18 X-CID-META: VersionHash:5d391d7,CLOUDID:184d592f-1ab8-4133-9780-81938111c800,B ulkID:240119175000U37AOBT2,BulkQuantity:0,Recheck:0,SF:19|44|101|66|38|24| 100|17|102,TC:nil,Content:0,EDM:-3,IP:-2,URL:11|1,File:nil,Bulk:nil,QS:nil ,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_ULN,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD, TF_CID_SPAM_FSI X-UUID: 32f247eb48334c838525b049013cc8ba-20240119 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw (envelope-from <chentao@kylinos.cn>) (Generic MTA) with ESMTP id 592375814; Fri, 19 Jan 2024 17:49:57 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 96CFEE000EB9; Fri, 19 Jan 2024 17:49:57 +0800 (CST) X-ns-mid: postfix-65AA45C5-4977541798 Received: from kernel.. (unknown [172.20.15.234]) by mail.kylinos.cn (NSMail) with ESMTPA id F1FC7E000EB9; Fri, 19 Jan 2024 17:49:50 +0800 (CST) From: Kunwu Chan <chentao@kylinos.cn> To: jgross@suse.com, boris.ostrovsky@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>, kernel test robot <lkp@intel.com>, Markus Elfring <Markus.Elfring@web.de> Subject: [PATCH v3] x86/xen: Add some null pointer checking to smp.c Date: Fri, 19 Jan 2024 17:49:48 +0800 Message-Id: <20240119094948.275390-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788327903255457582 X-GMAIL-MSGID: 1788512054144058020 |
Series |
[v3] x86/xen: Add some null pointer checking to smp.c
|
|
Commit Message
Kunwu Chan
Jan. 19, 2024, 9:49 a.m. UTC
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202401161119.iof6BQsf-lkp@intel.com/
Suggested-by: Markus Elfring <Markus.Elfring@web.de>
---
Changes in v3:
- Remove rc initialization
- Simply error paths by adding a new label 'fail_mem'
Changes in v2:
- Initial rc and return errno in error paths
---
arch/x86/xen/smp.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
Comments
> kasprintf() returns a pointer to dynamically allocated memory > which can be NULL upon failure. Ensure the allocation was successful > by checking the pointer validity. … > --- > Changes in v3: > - Remove rc initialization > - Simply error paths by adding a new label 'fail_mem' … I became curious if you would like to simplify further source code places. > +++ b/arch/x86/xen/smp.c > @@ -65,6 +65,8 @@ int xen_smp_intr_init(unsigned int cpu) > char *resched_name, *callfunc_name, *debug_name; > > resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu); > + if (!resched_name) > + goto fail_mem; Would you like to add a blank line after such a statement? > per_cpu(xen_resched_irq, cpu).name = resched_name; … Please compare with your subsequent suggestion. … > @@ -101,6 +108,9 @@ int xen_smp_intr_init(unsigned int cpu) > } > > callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu); > + if (!callfunc_name) > + goto fail_mem; > + > per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name; … Regards, Markus
> kasprintf() returns a pointer to dynamically allocated memory > which can be NULL upon failure. Ensure the allocation was successful > by checking the pointer validity. How do you think about to refer to the function name instead of the file name in the patch subject? … > +++ b/arch/x86/xen/smp.c … > @@ -114,6 +124,8 @@ int xen_smp_intr_init(unsigned int cpu) > > return 0; > > + fail_mem: > + rc = -ENOMEM; > fail: > xen_smp_intr_free(cpu); > return rc; Is it currently preferred to start labels in the first text column? Regards, Markus
On 2024/1/20 22:45, Markus Elfring wrote: >> kasprintf() returns a pointer to dynamically allocated memory >> which can be NULL upon failure. Ensure the allocation was successful >> by checking the pointer validity. > > How do you think about to refer to the function name > instead of the file name in the patch subject? > The main goal is to assign a errno to rc. So use 'fail_mem is good to understand. > > … >> +++ b/arch/x86/xen/smp.c > … >> @@ -114,6 +124,8 @@ int xen_smp_intr_init(unsigned int cpu) >> >> return 0; >> >> + fail_mem: >> + rc = -ENOMEM; >> fail: >> xen_smp_intr_free(cpu); >> return rc; > > Is it currently preferred to start labels in the first text column? Just the same as the old one. I could fix it if necessary. > > Regards, > Markus
On 2024/1/19 18:40, Markus Elfring wrote: >> kasprintf() returns a pointer to dynamically allocated memory >> which can be NULL upon failure. Ensure the allocation was successful >> by checking the pointer validity. > … >> --- >> Changes in v3: >> - Remove rc initialization >> - Simply error paths by adding a new label 'fail_mem' > … > > I became curious if you would like to simplify further source code places. This function hasn't changed in years, so it's OK for now. > > >> +++ b/arch/x86/xen/smp.c >> @@ -65,6 +65,8 @@ int xen_smp_intr_init(unsigned int cpu) >> char *resched_name, *callfunc_name, *debug_name; >> >> resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu); >> + if (!resched_name) >> + goto fail_mem; > > Would you like to add a blank line after such a statement? Sure, I could do it in next patch. > > >> per_cpu(xen_resched_irq, cpu).name = resched_name; > … > > Please compare with your subsequent suggestion. I’ve seend a reply. > > … >> @@ -101,6 +108,9 @@ int xen_smp_intr_init(unsigned int cpu) >> } >> >> callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu); >> + if (!callfunc_name) >> + goto fail_mem; >> + >> per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name; > … > > Regards, > Markus
>> How do you think about to refer to the function name >> instead of the file name in the patch subject? >> > The main goal is to assign a errno to rc. So use 'fail_mem is good to understand. You responded with information which can fit to the patch body. How do you think about consequences for a subject variant like the following? x86/xen: Add some null pointer checks in xen_smp_intr_init() Regards, Markus
On 19.01.24 10:49, Kunwu Chan wrote: > kasprintf() returns a pointer to dynamically allocated memory > which can be NULL upon failure. Ensure the allocation was successful > by checking the pointer validity. > > Signed-off-by: Kunwu Chan <chentao@kylinos.cn> > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/oe-kbuild-all/202401161119.iof6BQsf-lkp@intel.com/ > Suggested-by: Markus Elfring <Markus.Elfring@web.de> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c index 4b0d6fff88de..1fb9a1644d94 100644 --- a/arch/x86/xen/smp.c +++ b/arch/x86/xen/smp.c @@ -65,6 +65,8 @@ int xen_smp_intr_init(unsigned int cpu) char *resched_name, *callfunc_name, *debug_name; resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu); + if (!resched_name) + goto fail_mem; per_cpu(xen_resched_irq, cpu).name = resched_name; rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, cpu, @@ -77,6 +79,8 @@ int xen_smp_intr_init(unsigned int cpu) per_cpu(xen_resched_irq, cpu).irq = rc; callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu); + if (!callfunc_name) + goto fail_mem; per_cpu(xen_callfunc_irq, cpu).name = callfunc_name; rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR, cpu, @@ -90,6 +94,9 @@ int xen_smp_intr_init(unsigned int cpu) if (!xen_fifo_events) { debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu); + if (!debug_name) + goto fail_mem; + per_cpu(xen_debug_irq, cpu).name = debug_name; rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, xen_debug_interrupt, @@ -101,6 +108,9 @@ int xen_smp_intr_init(unsigned int cpu) } callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu); + if (!callfunc_name) + goto fail_mem; + per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name; rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR, cpu, @@ -114,6 +124,8 @@ int xen_smp_intr_init(unsigned int cpu) return 0; + fail_mem: + rc = -ENOMEM; fail: xen_smp_intr_free(cpu); return rc;