Received: by 10.213.65.68 with SMTP id h4csp1705419imn; Sun, 8 Apr 2018 09:32:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/FkEY0VQS+cepfSByWaec5dlHh73Xb4OYp/G1CFIHoGEB0A68meWrlt+GPCxnP8wnjW6VQ X-Received: by 2002:a17:902:c6:: with SMTP id a64-v6mr35160770pla.408.1523205147187; Sun, 08 Apr 2018 09:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523205147; cv=none; d=google.com; s=arc-20160816; b=tTzDkwOHWTqAJqdUg/avQ5eQqQimi22QVkwvwOvU2WoaaP5ie0cGYkhzD7HttNEcxz vrfZW8fgyt0Ej6j/qHBLh62ke6R7p59+fOLx4HkYhGWt71d07RR/QAozhe5QohZos/pW FM6aOGgVjItGr9kYvt5D61cnhlvfhXrkCwsJI+zqDmtuMRORKAMK0GrLvXBQh3+icvxQ UPtOM7nhs3d46gos5TrYvt7HgR6Om44vXSzRzW4RKv1Fivck/tiPfIM3Eb1apsVAatat Jkvd39muQKUYM72tvCKu7n0ddm+/rY2A83JOcAMot+4Wzx5Sw8v8QYb5bSwemBrvjRL8 bYMA== 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:in-reply-to :mime-version:user-agent:date:message-id:openpgp:from:references:cc :to:subject:arc-authentication-results; bh=MO+Piktuvha9QD7U5ClMYDXPCl8dSm4je9mmRQVF4L4=; b=o4/y1qsR6KpPDrvkkNbCPjqOj254nw+xNbAJrJM/UojcdGjTk//34F+O4GVDwO1hKK P7PGaIFKmPTGdPLcwpKY8JKCW25KbByN9WNIURB0b2KDjApNqUzKbJAExUop9uyMTiXW DAicCSdYlXhEkWeEGjlxd5tlep5k27/L4A0anfAyKdXGSBHegBrSTQD0MwlCgTUYYFAq AMxlKaTtBFNZxaZd0tEvPVKlQ2cL96o+0AGQjhSYUO4nz2eWXA8X0I80iuCuVPOguXvz ysnvf6P+QRNNNIcxxIqH3pp9acRjDh9auhZ8TxCe31uNrfyTA36/3EOM7wXjGp6TKBpD Pqsw== 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 n11-v6si15013585plg.236.2018.04.08.09.31.50; Sun, 08 Apr 2018 09:32:27 -0700 (PDT) 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 S1751799AbeDHPWw (ORCPT + 99 others); Sun, 8 Apr 2018 11:22:52 -0400 Received: from dd39320.kasserver.com ([85.13.155.146]:46290 "EHLO dd39320.kasserver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751552AbeDHPWv (ORCPT ); Sun, 8 Apr 2018 11:22:51 -0400 Received: from [192.168.0.46] (109.125.99.188.dynamic.cablesurf.de [109.125.99.188]) by dd39320.kasserver.com (Postfix) with ESMTPSA id 92A802CE0037; Sun, 8 Apr 2018 17:22:48 +0200 (CEST) Subject: Re: [PATCH] staging: pi433: add descriptions for mutex locks To: Valentin Vidic , Marcus Wolf Cc: Greg Kroah-Hartman , =?UTF-8?Q?Simon_Sandstr=c3=b6m?= , Marcus Wolf , =?UTF-8?Q?Luca_S=c3=b6the?= , Marcin Ciupak , Michael Panzlaff , Derek Robson , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20180323094725.4904-1-Valentin.Vidic@CARNet.hr> <20180323114254.GL31333@gavran.carpriv.carnet.hr> <9442615c-5606-328a-f8cc-ad389af55ee3@smarthome-wolf.de> <20180323180027.GM31333@gavran.carpriv.carnet.hr> <20180323221821.GP31333@gavran.carpriv.carnet.hr> <8544b858-673f-0f59-0d8b-0474036068ce@smarthome-wolf.de> <20180325130944.GU31333@gavran.carpriv.carnet.hr> From: Marcus Wolf Openpgp: preference=signencrypt Message-ID: <68bb0145-b144-b442-7ff3-c6080e44f377@smarthome-wolf.de> Date: Sun, 8 Apr 2018 17:22:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180325130944.GU31333@gavran.carpriv.carnet.hr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Valentin, like promissed, I finally had a deeper look to your proposal with kfifo_avail and your patch from 24th of March. In principle, I think it is a very nice idea, and we should try to implement it. But there is a snag: There is no guarantee, that kfifo_in will only fail, if the fifo is full. If there will be any another reason for kfifo_in to fail, with the new implementation there will be no handling for that. But I think the chance of such an situation is low to impossible and the win in simplicity of the code is really great. Regarding your patch, I did not understand, why you did not remove the mutex_lock in pi433_write. Wasn't it the goal to remove it? Below find a proposal of pi433_write function, I wrote on base of my outdated (!), private repo. It is not compiled and not tested. Since there is no more handling in case of an error (as well in the propsal as in your patch), I removed the error handling completely. I only do a test to detect proplems while writing to the tx_fifo, but (like in your patch) do nothing for solving, just printing a line. If this unexpected situation will occur (most probably never), the tx_fifo will be (and stay) out of sync until driver gets unloaded. We have to decide, whether we can stay with that. Like written above, I thinkt the benefits are great, the chance of such kind of error very low. What do you think? It could be discussed, whether it is better to return EMSGSIZE or EAGAIN on the first check. On the one hand, there is a problem with the message size, on the other hand (if message isn't generally too big) after a while, there should be some more space available in fifo, so EAGAIN may be better choice. static ssize_t pi433_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { struct pi433_instance *instance; struct pi433_device *device; int required, copied, retval; instance = filp->private_data; device = instance->device; /* check whether there is enough space available in tx_fifo */ required = sizeof(instance->tx_cfg) + sizeof(size_t) + count; if ( num_of_bytes_to_store_in_fifo > kfifo_avail(&device->tx_fifo) ) { dev_dbg(device->dev, "Not enough space in fifo. Need %d, but only have" , required , kfifo_avail(&device->tx_fifo) ); return -EMSGSIZE; } /* write the following sequence into fifo: * - tx_cfg * - size of message * - message */ retval = kfifo_in(&device->tx_fifo, &instance->tx_cfg, sizeof(instance->tx_cfg)); retval += kfifo_in (&device->tx_fifo, &count, sizeof(size_t)); retval += kfifo_from_user(&device->tx_fifo, buf, count, &copied); if (retval != required ) { dev_dbg(device->dev, "write to fifo failed, reason unknown, non recoverable."); return -EAGAIN; } /* start transfer */ wake_up_interruptible(&device->tx_wait_queue); dev_dbg(device->dev, "write: generated new msg with %d bytes.", copied); return 0; } Hope this helps :-) Marcus Am 25.03.2018 um 15:09 schrieb Valentin Vidic: > On Sun, Mar 25, 2018 at 03:00:09PM +0200, Marcus Wolf wrote: >> Unfortunaly I can't find the time to have a closer look on the code this >> weekend - still busy with tax stuff :-( >> >> Idea sounds great. I'll try to look at the code and think about it >> during Easter hollidays. > > No problem, there is no hurry. But please do test the patch I sent yesterday: > > [PATCH] staging: pi433: cleanup tx_fifo locking > > As I don't have the hardware this is just compile tested now :) >