From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754908Ab0JGX1w (ORCPT ); Thu, 7 Oct 2010 19:27:52 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:51216 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753451Ab0JGX1v (ORCPT ); Thu, 7 Oct 2010 19:27:51 -0400 Date: Thu, 7 Oct 2010 16:27:02 -0700 From: Andrew Morton To: Jerome Marchand Cc: Matthew Wilcox , Pavel Emelyanov , Linux Kernel Mailing List , xiyou.wangcong@gmail.com Subject: Re: [PATCH v2] procfs: fix numbering in /proc/locks Message-Id: <20101007162702.7db08f5b.akpm@linux-foundation.org> In-Reply-To: <4CAB1693.2080301@redhat.com> References: <4CA484BA.7090809@redhat.com> <4CAB1693.2080301@redhat.com> X-Mailer: Sylpheed 2.4.8 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 05 Oct 2010 14:14:11 +0200 Jerome Marchand wrote: > On 09/30/2010 02:38 PM, Jerome Marchand wrote: > > > > The lock number in /proc/locks (first field) is implemented by a counter > > (private field of struct seq_file) which is incremented at each call of > > locks_show() and reset to 1 in locks_start() whatever the offset is. It > > should be reset according to the actual position in the list. > > > > Moreover, locks_show() can be called twice to print a single line thus > > skipping a number. The counter should be incremented in locks_next(). > > > > Signed-off-by: Jerome Marchand > > --- > > locks.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/fs/locks.c b/fs/locks.c > > index ab24d49..49d7343 100644 > > --- a/fs/locks.c > > +++ b/fs/locks.c > > @@ -2166,19 +2166,19 @@ static int locks_show(struct seq_file *f, void *v) > > list_for_each_entry(bfl, &fl->fl_block, fl_block) > > lock_get_status(f, bfl, (long)f->private, " ->"); > > > > - f->private++; > > return 0; > > } > > > > static void *locks_start(struct seq_file *f, loff_t *pos) > > { > > lock_kernel(); > > - f->private = (void *)1; > > + f->private = (void *) (*pos + 1); > > That cast trigger a warning on some arch: > "warning: cast to pointer from integer of different size" > > There is no real risk here. At worst /proc/locks will show wrong number > if there is more than 2^32 locks, but should I mute the warning it with > something like: > f->private = (void *) (size_t) (*pos + 1); > ? Putting a loff_t into a void* is a pretty alarming thing to do. If we're really going to do that then use a (long) cast and put a very good comment at the code site explaining why the bug doesn't matter, so people aren't misled. But really, why sweat it? kmalloc the eight bytes, make ->private point at that and we never have to think about it again. Bonus points for doing this without any typecasts ;)