Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751285AbdH1Ewp (ORCPT ); Mon, 28 Aug 2017 00:52:45 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37677 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750866AbdH1Ewo (ORCPT ); Mon, 28 Aug 2017 00:52:44 -0400 Date: Sun, 27 Aug 2017 21:52:38 -0700 From: Sukadev Bhattiprolu To: Michael Ellerman Cc: Benjamin Herrenschmidt , mikey@neuling.org, stewart@linux.vnet.ibm.com, apopple@au1.ibm.com, hbabu@us.ibm.com, oohall@gmail.com, linuxppc-dev@ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 06/12] powerpc/vas: Define helpers to alloc/free windows References: <1503556688-15412-1-git-send-email-sukadev@linux.vnet.ibm.com> <1503556688-15412-7-git-send-email-sukadev@linux.vnet.ibm.com> <878ti8uh0r.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878ti8uh0r.fsf@concordia.ellerman.id.au> X-Operating-System: Linux 2.0.32 on an i486 User-Agent: Mutt/1.7.1 (2016-10-04) X-TM-AS-GCONF: 00 x-cbid: 17082804-0008-0000-0000-0000087C201B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007625; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000225; SDB=6.00908651; UDB=6.00455616; IPR=6.00688891; BA=6.00005555; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016893; XFM=3.00000015; UTC=2017-08-28 04:52:42 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082804-0009-0000-0000-000043BD6263 Message-Id: <20170828045238.GD12907@us.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-28_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708280077 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2028 Lines: 86 Michael Ellerman [mpe@ellerman.id.au] wrote: > Sukadev Bhattiprolu writes: > > diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c > > + rc = ida_pre_get(ida, GFP_KERNEL); > > + if (!rc) > > + return -EAGAIN; > > + > > + spin_lock(&vas_ida_lock); > > + rc = ida_get_new_above(ida, 0, &winid); > > If you're passing 0 you can just use ida_get_new(). Ok. > > Or did you actually want to exclude 0? In which case you should pass 1. > > > + spin_unlock(&vas_ida_lock); > > + > > + if (rc) > > + return rc; > > You're supposed to handle EAGAIN I thought. Yes, I will retry the pre_get() > > > + > > + if (winid > VAS_WINDOWS_PER_CHIP) { > > + pr_err("VAS: Too many (%d) open windows\n", winid); > > + vas_release_window_id(ida, winid); > > + return -EAGAIN; > > + } > > + > > + return winid; > > +} > > + > > +void vas_window_free(struct vas_window *window) > > static. Ok > > > +{ > > + int winid = window->winid; > > + struct vas_instance *vinst = window->vinst; > > + > > + unmap_winctx_mmio_bars(window); > > + kfree(window); > > + > > + vas_release_window_id(&vinst->ida, winid); > > +} > > + > > +struct vas_window *vas_window_alloc(struct vas_instance *vinst) > > +{ > > + int winid; > > + struct vas_window *window; > > + > > + winid = vas_assign_window_id(&vinst->ida); > > + if (winid < 0) > > + return ERR_PTR(winid); > > + > > + window = kzalloc(sizeof(*window), GFP_KERNEL); > > + if (!window) > > + return ERR_PTR(-ENOMEM); > > You leak an id here. Argh. Yes. > > The error handling would be easier in here if the caller did the alloc, > or if you split alloc and init, and alloc just did the kzalloc(). I was trying to simplify error handling in the callers where they have to only deal with one failure now. > > One of the callers even prints "unable to allocate memory" if this > function fails, but that's not accurate, there's several failure modes. Yes, will fix that message and the leaks. Thanks, Suka