Received: by 10.223.176.5 with SMTP id f5csp146907wra; Fri, 26 Jan 2018 19:47:03 -0800 (PST) X-Google-Smtp-Source: AH8x227sxkoOmwgpxqiLi9jtKYtgguCjEIhwHA5m8GOSy+zg9J6HdE75ke5mTCEVWcHqHY3Ko/Sl X-Received: by 10.98.71.197 with SMTP id p66mr20919737pfi.3.1517024823487; Fri, 26 Jan 2018 19:47:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517024823; cv=none; d=google.com; s=arc-20160816; b=QYXBK6y1UAoIC4YS/KgmmT5E+Wjx5+mfVEh7LIwpNUNkvSg0g7dtZ3g5PaX4Gcz4ca 6iREbkWEvjUWIHRy/zGfYBUo76oe1eCJqsHeXxVHQJ1cRHWuuFUHC2Dl+9crhDrD1Bjd ioN2L2Wsj/txgQjCmA6IBpWNKtGrKUTO7ECiCVj5jLO8eGg/wLJPYBebtWgqPTL5ASDn 7eIXkwIngG1Sev/seAOXbBVJDUtzSapT20ERMsiANbTw5pSkp807jg8c9cRavw2Bev1X nTpFEk2N71zfWm57Eckbos+RvVNw53sUABHRym30GJqLIgpST8pM9Q43tj+DVXEr/Jig VMmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from:arc-authentication-results; bh=9alUhHblrx+1pOG60AlIFFAzRqt4tvpVxcjV87igFIE=; b=cINVcO9N+qp/az9sYORlnQocfnekrYK71T19gws75ZnzkeMuPYl8nsyG3Zx1rgoeX6 6ekQxRbWx64CE+2+T2dvZAPcfXyj+zz/x55/AdRrtAcVLaRtYwQaZp1EE1J9BuErYbLG lxnCIeNzOhBR0lV/xnqmDeXtlNUhmakzs/YsT8X5Hv6uEPkJCjhstZNV8Pxs72MNpM6s Bvm/mFo4njVYoTApZu6bakgm6NTnPxUjjYh7VL2fg4+6NxRsq5zHStkEOK3YByT5BudW K1mWho+J3ppbUgvgyQezOWBXC6FbLH2+ZosdTjxs4cvCr4kVleeFh1ORgQowc0lGMyQV EcgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si3895122pgo.550.2018.01.26.19.46.49; Fri, 26 Jan 2018 19:47:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752019AbeA0DpD convert rfc822-to-8bit (ORCPT + 99 others); Fri, 26 Jan 2018 22:45:03 -0500 Received: from mga11.intel.com ([192.55.52.93]:51090 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925AbeA0DpB (ORCPT ); Fri, 26 Jan 2018 22:45:01 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jan 2018 19:45:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,420,1511856000"; d="scan'208";a="199180077" Received: from adixit-mobl.amr.corp.intel.com (HELO adixit-arch.ra.intel.com) ([10.254.75.181]) by fmsmga006.fm.intel.com with ESMTP; 26 Jan 2018 19:45:00 -0800 From: Ashutosh Dixit To: Al Viro Cc: Christopher =?utf-8?Q?D=C3=ADaz?= Riveros , "Dutt\, Sudeep" , "arnd\@arndb.de" , "gregkh\@linuxfoundation.org" , "linux-kernel\@vger.kernel.org" , "kernel-janitors\@vger.kernel.org" Subject: Re: [PATCH-next] misc: mic: Use PTR_ERR_OR_ZERO References: <20180123201009.12998-1-chrisadr@gentoo.org> <20180123215519.GP13338@ZenIV.linux.org.uk> Date: Fri, 26 Jan 2018 19:45:00 -0800 In-Reply-To: <20180123215519.GP13338@ZenIV.linux.org.uk> (Al Viro's message of "Tue, 23 Jan 2018 14:55:19 -0700") Message-ID: <87shasezib.fsf@intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 23 2018 at 02:55:19 PM, Al Viro wrote: > On Tue, Jan 23, 2018 at 03:10:09PM -0500, Christopher Díaz Riveros wrote: >> Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR >> >> This issue was detected by using the Coccinelle software. > > ... and that's a wonderful demonstration of the reasons why PTR_ERR_OR_ZERO() > is in bad taste. > > Look at the callers of that sucker: > > err = scif_anon_inode_getfile(ep); > if (err) > goto err_anon_inode; > > and > > err = scif_anon_inode_getfile(cep); > if (err) > goto scif_accept_error_anon_inode; > > See the problem? What really happens here is that we > * call anon_inode_getfile() and stick the result into ->anon. > * if that was ERR_PTR(), we bugger off > > Checking that PTR_ERR_OR_ZERO() is non-zero is a bloody convoluted way of > spelling > if (IS_ERR(...)) { > err = PTR_ERR(...); > goto sod_off; > } > > Your change preserves the ugliness of the original calling conventions; > the mistake here is making it return an int. Add the fact that > all (both) callers are in drivers/misc/mic/scif/scif_api.c and take > a look at this: > ; git grep -n -w scif_anon_fops > drivers/misc/mic/scif/scif_api.c:47:const struct file_operations scif_anon_fops = { > drivers/misc/mic/scif/scif_epd.h:167: epd->anon = anon_inode_getfile("scif", &scif_anon_fops, NULL, 0); > drivers/misc/mic/scif/scif_main.h:213:extern const struct file_operations scif_anon_fops; > ; > > So scif_anon_fops is > * defined in scif_api.c > * declared in scif_main.h > * used only in an inline function defined in scif_epd.h, which is used > only in scif_api.c > > Could you spell "way too convoluted"? > > Please, do the following: move that sucker scif_api.c, and make it return > struct file *. As in return epd->anon = anon_inode_getfile(...); > And turn the callers into > if (IS_ERR(whatever_you_call_it(ep))) { > err = PTR_ERR(ep->anon); > goto ...; > } > Then make scif_anon_fops static and kill that extern in scif_main.h. > > What the hell? for callers of scif_poll()> > > Let me see if I got it right - *ALL* callers of that thing pass it > an array consisting of 1 (one) entry. So playing with poll_wqueues > and __pollwait() is utterly pointless in scif_poll(). So is grabbing > references to that struct file, BTW, regardless of everything else. > And so is having the bloody ->anon at all - __scif_pollfd() should be > passed NULL as the first argument and that's it. All it takes is > a separate queue callback set via init_poll_funcptr() and to hell > with all those complication. Oh, and since we don't really need > dynmic allocations inside that queue callback, table.error crap > also goes to hell... > > Incidentally, since this is one of the two places outside of fs/select.c > using poll_{init,free}wait(), we can bloody well unexport those - the > other caller (in drivers/staging/farce^Wcomedi) also uses it for > single struct file, pinned by the caller. And while we are at it, > that would also make struct poll_wqueues private to fs/select.c... > > Could Intel folks describe the planned future uses of scif_poll()? > If it's not going to be used for large sets, the whole thing could > be simplified quite nicely... Cleanups and suggestions to improve the code such as those outlined at the top of this reply are of course welcome. The SCIF API has both user and kernel space clients, and the kernel API mirrors the user space API. Similar to user space poll which supports multiple file descriptors, the kernel client poll API was designed to allow poll on multiple SCIF endpoints as well. Since the API has been stable for a couple of years now, our preference is to preserve the API as far as possible.