From nobody Mon Feb 9 02:28:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1606810926; cv=none; d=zohomail.com; s=zohoarc; b=avKQp4yYB9Fw+6MUwKx+kv3SF5ev5/0nznYlJIA5cThyguARhxTK1RP+jAF/IKedosQtraYUWJ6G+NlJilsVnejUsK60oLaYb6q4kDtaSlaY/0ojf+De6sDopyXWXYjo3I3FUMPh9mdilaSFNqw58/Ok8PZsyHjaAU2Q0fKLGuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606810926; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GDlThUHp1khXcMw14yFbWzJcy5msoaFCmMjGVwghDTw=; b=Zb3fxUYvrIt/2NCUBukMu/VGlVQLabzZdAOp5SB9a841OokYmfyXA9NAR7NMfivyw0wi+OcDSh6UeELJX1c3Drw6FhvmWKul4wpLGw8mT/KydwLkuhblfrvSuxITna0CAIP31NKvor/sbuwvkuAjVdkXm55zrgWOIqvDVkdLKuo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1606810926658295.7964854601249; Tue, 1 Dec 2020 00:22:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.41629.74982 (Exim 4.92) (envelope-from ) id 1kk0uz-0004tc-4z; Tue, 01 Dec 2020 08:21:49 +0000 Received: by outflank-mailman (output) from mailman id 41629.74982; Tue, 01 Dec 2020 08:21:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kk0uz-0004tT-0C; Tue, 01 Dec 2020 08:21:49 +0000 Received: by outflank-mailman (input) for mailman id 41629; Tue, 01 Dec 2020 08:21:47 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kk0ux-0004VK-5f for xen-devel@lists.xenproject.org; Tue, 01 Dec 2020 08:21:47 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 47543d46-c993-4e43-b9b2-580602c148f4; Tue, 01 Dec 2020 08:21:33 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 08B27ADB3; Tue, 1 Dec 2020 08:21:32 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 47543d46-c993-4e43-b9b2-580602c148f4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1606810892; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GDlThUHp1khXcMw14yFbWzJcy5msoaFCmMjGVwghDTw=; b=RIPBYEVfMZ0L6sdH0/scPIO3SUWJ8lAPqqmZDol9/cWCRirYglJ1FgSX3NSmO3Nu5pX/Lq 4WFVSznlXIbgXjQ2yZ9id3JAVFzKg0DdKbWCHcvMaUAB8PRGhVyc3eV/Rwol412BKcfIOD ikPqSQ/8m2KDtAfgCoLyP1ZQYOA4A+U= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , George Dunlap , Dario Faggioli Subject: [PATCH v2 06/17] xen/cpupool: use ERR_PTR() for returning error cause from cpupool_create() Date: Tue, 1 Dec 2020 09:21:17 +0100 Message-Id: <20201201082128.15239-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201201082128.15239-1-jgross@suse.com> References: <20201201082128.15239-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Instead of a pointer to an error variable as parameter just use ERR_PTR() to return the cause of an error in cpupool_create(). This propagates to scheduler_alloc(), too. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli Reviewed-by: Jan Beulich --- V2: - new patch --- xen/common/sched/core.c | 13 ++++++------- xen/common/sched/cpupool.c | 38 ++++++++++++++++++++------------------ xen/common/sched/private.h | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 6063f6d9ea..a429fc7640 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -3233,26 +3233,25 @@ struct scheduler *scheduler_get_default(void) return &ops; } =20 -struct scheduler *scheduler_alloc(unsigned int sched_id, int *perr) +struct scheduler *scheduler_alloc(unsigned int sched_id) { int i; + int ret; struct scheduler *sched; =20 for ( i =3D 0; i < NUM_SCHEDULERS; i++ ) if ( schedulers[i] && schedulers[i]->sched_id =3D=3D sched_id ) goto found; - *perr =3D -ENOENT; - return NULL; + return ERR_PTR(-ENOENT); =20 found: - *perr =3D -ENOMEM; if ( (sched =3D xmalloc(struct scheduler)) =3D=3D NULL ) - return NULL; + return ERR_PTR(-ENOMEM); memcpy(sched, schedulers[i], sizeof(*sched)); - if ( (*perr =3D sched_init(sched)) !=3D 0 ) + if ( (ret =3D sched_init(sched)) !=3D 0 ) { xfree(sched); - sched =3D NULL; + sched =3D ERR_PTR(ret); } =20 return sched; diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index 714cd47ae9..0db7d77219 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -240,15 +240,15 @@ void cpupool_put(struct cpupool *pool) * - poolid already used * - unknown scheduler */ -static struct cpupool *cpupool_create( - unsigned int poolid, unsigned int sched_id, int *perr) +static struct cpupool *cpupool_create(unsigned int poolid, + unsigned int sched_id) { struct cpupool *c; struct cpupool *q; + int ret; =20 - *perr =3D -ENOMEM; if ( (c =3D alloc_cpupool_struct()) =3D=3D NULL ) - return NULL; + return ERR_PTR(-ENOMEM); =20 /* One reference for caller, one reference for cpupool_destroy(). */ atomic_set(&c->refcnt, 2); @@ -267,7 +267,7 @@ static struct cpupool *cpupool_create( list_add_tail(&c->list, &q->list); if ( q->cpupool_id =3D=3D poolid ) { - *perr =3D -EEXIST; + ret =3D -EEXIST; goto err; } } @@ -294,15 +294,15 @@ static struct cpupool *cpupool_create( } =20 if ( poolid =3D=3D 0 ) - { c->sched =3D scheduler_get_default(); - } else + c->sched =3D scheduler_alloc(sched_id); + if ( IS_ERR(c->sched) ) { - c->sched =3D scheduler_alloc(sched_id, perr); - if ( c->sched =3D=3D NULL ) - goto err; + ret =3D PTR_ERR(c->sched); + goto err; } + c->sched->cpupool =3D c; c->gran =3D opt_sched_granularity; c->sched_gran =3D sched_granularity; @@ -312,15 +312,16 @@ static struct cpupool *cpupool_create( debugtrace_printk("Created cpupool %u with scheduler %s (%s)\n", c->cpupool_id, c->sched->name, c->sched->opt_name); =20 - *perr =3D 0; return c; =20 err: list_del(&c->list); =20 spin_unlock(&cpupool_lock); + free_cpupool_struct(c); - return NULL; + + return ERR_PTR(ret); } /* * destroys the given cpupool @@ -767,7 +768,7 @@ static void cpupool_cpu_remove_forced(unsigned int cpu) */ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op) { - int ret; + int ret =3D 0; struct cpupool *c; =20 switch ( op->op ) @@ -779,8 +780,10 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op) =20 poolid =3D (op->cpupool_id =3D=3D XEN_SYSCTL_CPUPOOL_PAR_ANY) ? CPUPOOLID_NONE: op->cpupool_id; - c =3D cpupool_create(poolid, op->sched_id, &ret); - if ( c !=3D NULL ) + c =3D cpupool_create(poolid, op->sched_id); + if ( IS_ERR(c) ) + ret =3D PTR_ERR(c); + else { op->cpupool_id =3D c->cpupool_id; cpupool_put(c); @@ -1003,12 +1006,11 @@ static struct notifier_block cpu_nfb =3D { static int __init cpupool_init(void) { unsigned int cpu; - int err; =20 cpupool_gran_init(); =20 - cpupool0 =3D cpupool_create(0, 0, &err); - BUG_ON(cpupool0 =3D=3D NULL); + cpupool0 =3D cpupool_create(0, 0); + BUG_ON(IS_ERR(cpupool0)); cpupool_put(cpupool0); register_cpu_notifier(&cpu_nfb); =20 diff --git a/xen/common/sched/private.h b/xen/common/sched/private.h index 6953cefa6e..92d0d49610 100644 --- a/xen/common/sched/private.h +++ b/xen/common/sched/private.h @@ -597,7 +597,7 @@ void sched_rm_cpu(unsigned int cpu); const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int c= pu); void schedule_dump(struct cpupool *c); struct scheduler *scheduler_get_default(void); -struct scheduler *scheduler_alloc(unsigned int sched_id, int *perr); +struct scheduler *scheduler_alloc(unsigned int sched_id); void scheduler_free(struct scheduler *sched); int cpu_disable_scheduler(unsigned int cpu); int schedule_cpu_add(unsigned int cpu, struct cpupool *c); --=20 2.26.2