From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, T_DKIMWL_WL_HIGH,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F87EC04AB5 for ; Thu, 6 Jun 2019 13:28:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25E2B20866 for ; Thu, 6 Jun 2019 13:28:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dshXaScN"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="0yjG6Bdd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25E2B20866 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NwIxdbOicSLHc4RcvtTuOIE+2sm+QfSLOYRaTGC3qRM=; b=dshXaScN/6DPZV 7/iFKU2daTfoNr+OMm2e8wv5aDM9bzkdmUcV4t9qpWMjmKTtlq/9cXPmf/2es7o8TCv2cxsEAHYiV mQI09aCcw0Hw5elS8iN8yZScQqCLPGrvUBFbsni/c+yMsxw6D4xEYx9uujLTO3NDUtyT6LR9l9KAj lj2n68TsSahLVCXHznRPxKG4+3+HnXH8M2Ney74KSz7rIRmMo3cuchynwEaNLqquZL36KSzUCfFPI jZBdlIgqeMwV4Ghgh/m4APioVTJaaUZRMqsA4xaUOUzZaqHkZLiGC2l6fWnoaMEiUfElBImBkVwVF yG1k/68mJYhCxozPuxXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYsRl-0007uZ-3Z; Thu, 06 Jun 2019 13:28:49 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYsRh-0007tq-Ey for linux-arm-kernel@lists.infradead.org; Thu, 06 Jun 2019 13:28:46 +0000 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A539D20866; Thu, 6 Jun 2019 13:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559827725; bh=UHWrtQgpvixRqPbEtkrChsh4DvWxscCBoV1YMgNBxGg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0yjG6Bddq99LhfiaYiI3rJevdiHeIpzCUmVUfkqh052ofns7xizCLJEEC9QW8AWiR KwnSd5ZR1pPhnX7ZbkgIru9bVWnT57pk77L+901o8LE12SSIIYQfwZaXMVJHPetSEF qLNBBwl2a5cdhPnL08ZRoTAHkkoZZn9s0Ju27f2w= Date: Thu, 6 Jun 2019 15:28:42 +0200 From: Greg KH To: Dragan Cvetic Subject: Re: [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl Message-ID: <20190606132842.GC7943@kroah.com> References: <1558784245-108751-1-git-send-email-dragan.cvetic@xilinx.com> <1558784245-108751-5-git-send-email-dragan.cvetic@xilinx.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1558784245-108751-5-git-send-email-dragan.cvetic@xilinx.com> User-Agent: Mutt/1.12.0 (2019-05-25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190606_062845_512887_37C02D35 X-CRM114-Status: GOOD ( 12.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, arnd@arndb.de, michal.simek@xilinx.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, Derek Kiernan , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, May 25, 2019 at 12:37:17PM +0100, Dragan Cvetic wrote: > +static int xsdfec_dev_open(struct inode *iptr, struct file *fptr) > +{ > + return 0; > +} > + > +static int xsdfec_dev_release(struct inode *iptr, struct file *fptr) > +{ > + return 0; > +} empty open/close functions are never needed, just drop them. > + > +static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd, > + unsigned long data) > +{ > + struct xsdfec_dev *xsdfec; > + void __user *arg = NULL; > + int rval = -EINVAL; > + > + xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev); > + if (!xsdfec) > + return rval; It is impossible for container_of() to return NULL, unless something very magical and rare just happened. It's just doing pointer math, you can never check the return value of it. > + > + if (_IOC_TYPE(cmd) != XSDFEC_MAGIC) > + return -ENOTTY; How can this happen? > + > + /* check if ioctl argument is present and valid */ > + if (_IOC_DIR(cmd) != _IOC_NONE) { > + arg = (void __user *)data; > + if (!arg) > + return rval; > + } > + > + switch (cmd) { > + default: > + /* Should not get here */ > + dev_warn(xsdfec->dev, "Undefined SDFEC IOCTL"); Nice that userspace has a way to fill up the kernel log :( Just return the correct error here, don't log it. thanks, greg k-h _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Subject: Re: [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl Date: Thu, 6 Jun 2019 15:28:42 +0200 Message-ID: <20190606132842.GC7943@kroah.com> References: <1558784245-108751-1-git-send-email-dragan.cvetic@xilinx.com> <1558784245-108751-5-git-send-email-dragan.cvetic@xilinx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1558784245-108751-5-git-send-email-dragan.cvetic@xilinx.com> Sender: linux-kernel-owner@vger.kernel.org To: Dragan Cvetic Cc: arnd@arndb.de, michal.simek@xilinx.com, linux-arm-kernel@lists.infradead.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Derek Kiernan List-Id: devicetree@vger.kernel.org On Sat, May 25, 2019 at 12:37:17PM +0100, Dragan Cvetic wrote: > +static int xsdfec_dev_open(struct inode *iptr, struct file *fptr) > +{ > + return 0; > +} > + > +static int xsdfec_dev_release(struct inode *iptr, struct file *fptr) > +{ > + return 0; > +} empty open/close functions are never needed, just drop them. > + > +static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd, > + unsigned long data) > +{ > + struct xsdfec_dev *xsdfec; > + void __user *arg = NULL; > + int rval = -EINVAL; > + > + xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev); > + if (!xsdfec) > + return rval; It is impossible for container_of() to return NULL, unless something very magical and rare just happened. It's just doing pointer math, you can never check the return value of it. > + > + if (_IOC_TYPE(cmd) != XSDFEC_MAGIC) > + return -ENOTTY; How can this happen? > + > + /* check if ioctl argument is present and valid */ > + if (_IOC_DIR(cmd) != _IOC_NONE) { > + arg = (void __user *)data; > + if (!arg) > + return rval; > + } > + > + switch (cmd) { > + default: > + /* Should not get here */ > + dev_warn(xsdfec->dev, "Undefined SDFEC IOCTL"); Nice that userspace has a way to fill up the kernel log :( Just return the correct error here, don't log it. thanks, greg k-h