From: Ingo Molnar Subject: Re: [PATCH 2/9] kvm tools: Add basic ioport dynamic allocation Date: Wed, 25 May 2011 16:34:42 +0200 Message-ID: <20110525143442.GB29179@elte.hu> References: <1306333427-26186-1-git-send-email-levinsasha928@gmail.com> <1306333427-26186-2-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: penberg@kernel.org, john@jfloren.net, kvm@vger.kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com To: Sasha Levin Return-path: Received: from mx2.mail.elte.hu ([157.181.151.9]:37479 "EHLO mx2.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932280Ab1EYOes (ORCPT ); Wed, 25 May 2011 10:34:48 -0400 Content-Disposition: inline In-Reply-To: <1306333427-26186-2-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: * Sasha Levin wrote: > +u16 ioport__find_free_range(void) > +{ > + static u16 cur_loc; Please don't put statics inside function bodies! (even if they are only used within a single function) I had to look three times to discover that it's really a global variable. These should be where other global variables are, or should be put before the function, in plain sight. Also, if you do that i'd suggest a more descriptive name - free_io_port_idx perhaps? > + return IOPORT_START + (cur_loc++ * IOPORT_SIZE); So this is SMP unsafe really. While ioport registrations are currently only used from initdev() functions and are thus serialized, it's not completely unfeasible that we would want to have async initcalls like the kernel does, to improve bootup/startup performance! So it would be nice to make this all SMP safe. A single mutex would suffice i suspect. Thanks, Ingo