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.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED, 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 22A35C43219 for ; Tue, 30 Apr 2019 12:07:45 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (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 D04DE205ED for ; Tue, 30 Apr 2019 12:07:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kroah.com header.i=@kroah.com header.b="jw+Gnh3C"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cl9ePkjc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D04DE205ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kroah.com Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.91) (envelope-from ) id 1hLRXl-00081V-RM; Tue, 30 Apr 2019 08:07:29 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hLRXj-00081O-UI for kernelnewbies@kernelnewbies.org; Tue, 30 Apr 2019 08:07:28 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id A9734738; Tue, 30 Apr 2019 08:07:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 30 Apr 2019 08:07:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=FqjLPdWhS5Zh0GSi2u0rEB5GJlN 24IMzNpy3EanL9w4=; b=jw+Gnh3C5lbccCamo1V8GuN3yTDFRd6mQ6ewdVb66Nw iK8vV9SgNx/sOk6uFiYMj1GRB+pFPbIJb18Db59PUJEuQotTIplljmZcNJAyE/V/ h5EbLiUu8QDlf0W0KJY23sjCEszvxCm/icYXS/QkKwpsjPjog6sRRZ/oxkyR2xv3 1GL5kflxFc/sYSiJRfyjuCXOyCZcDEQVorcZ9dg69jxXxyR/zp7CFICcOJELrBgb WmPEth59SHGTBCNISC2/HufOvUyVjJ/QPYM8XhQ2gjIiB8LYxCDtr4wbw7Hgl/PA dswRbtHSmkA6MXFKEnZsFKn3nH6eLLd1tbsl/4GRNOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=FqjLPd WhS5Zh0GSi2u0rEB5GJlN24IMzNpy3EanL9w4=; b=cl9ePkjck2Mmi42EdD66JL kjq02G2vZiKEpa3By0+GIsIZ+plzTdPeRHDgSIjF3i0Y/QJeuX7WV4DGI1eoQ3zh XNR+d6qUtFTb7U1eRQPiDxHXK1f/24ujknlrwB6lYlp3P2Uydg0CorAPoR+wbgI+ xODgGAOXh/Jo8TMhpiQh4h8EegXRAQ+w5llpRlqbZl1HA0Xj1EDmhMMxB+ZnfLom ooxS01zwRbueRGr6zMzhqhHsXHdBkRTuCHfuA/dPgOFXDO/eRrJnfvbqUl/qn2RP MV35XrEeLWUx7i9HxIjax2STT+SWB4hcztTukZaeoYKOeRItLAyMfOAW8uxZW3Jw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrieeggdeglecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjfgesthdtre dttdervdenucfhrhhomhepifhrvghgucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheq necukfhppeekfedrkeeirdekledruddtjeenucfrrghrrghmpehmrghilhhfrhhomhepgh hrvghgsehkrhhorghhrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 56F11103CA; Tue, 30 Apr 2019 08:07:22 -0400 (EDT) Date: Tue, 30 Apr 2019 14:07:20 +0200 From: Greg KH To: rdq@metamail.co Subject: Re: debugfs question ... Message-ID: <20190430120720.GA22892@kroah.com> References: <009001d4ff4a$2ac6a030$8053e090$@metamail.co> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <009001d4ff4a$2ac6a030$8053e090$@metamail.co> User-Agent: Mutt/1.11.4 (2019-03-13) Cc: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Tue, Apr 30, 2019 at 12:45:08PM +0100, rdq@metamail.co wrote: > Greetings, > > My I2C sensor driver has a debugfs entry for development purposes. > Everything works fine with the exception of the read operation. When 'cat' > is used, the read operation is called repeatedly and indefinitely. If the > read() is changed to return 0 then, as expected, nothing is displayed. > > The pattern for the implementation is (AFAICT) right out of the book (shown > below). > > What am I missing? Any thoughts much appreciated. > > TAIA. > > RDQ > > static ssize_t sc031gs_reg_read_file(struct file *file, char __user > *user_buf, > size_t count, loff_t *ppos) > { > char *buf = 0; > ssize_t total = 0; > struct sc031gs_dev *sensor = file->private_data; > if (!sensor) > return -EINVAL; > if (*ppos < 0 || !count) > return -EINVAL; > buf = kmalloc(count, GFP_KERNEL); > if (!buf) > return -ENOMEM; > total = snprintf(buf,count,"Hello world\n"); > if (total >= 0) { > if (copy_to_user(user_buf, buf, total)) { > kfree(buf); > return -EFAULT; > } > *ppos += total; > } > kfree(buf); > return total; > } You are returning a "short" read, and then disallowing ppos to be set to a non-zero value? That's a recipie for disaster :( Also, you allow userspace to allocate as much memory as it asks for? Not good :( Why not just use the simple_read_from_buffer() call? That handles all of the "housekeeping" for you, and your function can be _much_ simpler. good luck! greg k-h _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies