Received: by 10.192.165.156 with SMTP id m28csp493285imm; Thu, 19 Apr 2018 02:36:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ECVARebmrQX6o7kk+0wq2HUZaM3hHG7OP0rtjnmajL7aUAAhRaVmIdGrPszPrmkAgCFgp X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr5453405plc.248.1524130562269; Thu, 19 Apr 2018 02:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524130562; cv=none; d=google.com; s=arc-20160816; b=k6iHous4Q0Q72NiXJkEXQpig6ol3vUMvX0bfFzSx+7MOAO3IicwqWMBlbn9QLN7s9g JZxoGlZ7OXkgte/UCR4yC6uQFgL9uRiVXfzrcHzXgr3orIJNtB037CYPn+1c3M1HR0eS VcczGMaMv9usL9o66wGP88pf1Jlhoi2tdKJXJaCNxJPWX3TDHOxn/DIgziDQFDo8TOam Y+t13UpoKSr7X97ahKLnTWp2e5SkyIA4YCOCb0eQt87auhB7i7XLjoy4TDuhtjTLw6r2 YpbtbPuwhSB/OpP5K4eZOQK1YNNVP+HcdfOVadlSlBmNdwft51lzh18vlSvx6tEwbR8A BMTA== 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=K8KRRznj6NZ9unEtng5WW0EJt3Muju4rcaPwkx0gI3g=; b=xSjlBa2TLXAeh0/XWbPbjKQISFoLCIg4amCt+b2WdfY/cFNg1DBHGhSrqLYRIb+ePa wo4Jg4dw9tvrc4e6ELs0NMsrzKDiCBNoTWujVwS0ekhLG08sMdgUIozK+WTm3k6WlXyP BrBl6Jj3b1uEd6JtVZ3qC17vvrQTQ4Hh2ZOkaUF3oBZamenSI9qTlC3Yy+m0+jiw7mo/ mUZ+rRPbMGD32HtDbmI1WBTaEY7tN1/BOzem+bxuBfWJHoN3UV1rfrDbDRieGagrJ0MV uCNrtPLavspOiavD0bTlXgfBmBJvrURICNmsKZX1OyPP/F1JtHqYDK0DpCGU+6mo1gjC VTwA== 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 r3-v6si3696044pli.324.2018.04.19.02.35.48; Thu, 19 Apr 2018 02:36:02 -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 S1753132AbeDSJeF (ORCPT + 99 others); Thu, 19 Apr 2018 05:34:05 -0400 Received: from dd39320.kasserver.com ([85.13.155.146]:57854 "EHLO dd39320.kasserver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753092AbeDSJeC (ORCPT ); Thu, 19 Apr 2018 05:34:02 -0400 Received: from [192.168.0.32] (109.125.99.188.dynamic.cablesurf.de [109.125.99.188]) by dd39320.kasserver.com (Postfix) with ESMTPSA id 419992CE0040; Thu, 19 Apr 2018 11:34:00 +0200 (CEST) Subject: Re: [PATCH] staging: pi433: add descriptions for mutex locks To: Valentin Vidic 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> <68bb0145-b144-b442-7ff3-c6080e44f377@smarthome-wolf.de> <20180412184608.GV3257@gavran.carpriv.carnet.hr> From: Marcus Wolf Openpgp: preference=signencrypt Message-ID: <4dba7594-2661-edd5-24ba-cffdf24021c5@smarthome-wolf.de> Date: Thu, 19 Apr 2018 11:33:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180412184608.GV3257@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 Am 12.04.2018 um 20:46 schrieb Valentin Vidic: > On Sun, Apr 08, 2018 at 05:22:46PM +0200, Marcus Wolf wrote: >> 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? > > Is it possible for more than one userspace program to open the pi433 > device and send messages? In that case more than one pi433_write > could be running and it needs to hold a mutex_lock before calling > kfifo_in. You are right. The write function is open for multiple userspace programs. So mutex_lock schould remain. >> 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? > > Yes, if there is only one writer and it checks the available size, > kfifo_in should not fail. The only problem might be copy_from_user > but perhaps that is also quite unlikely. A workaround for that could > be to copy the data into a temporary kernel buffer first and than > start kfifo writes using only kernel memory. For my feeling, that's a safe solution but most probably oversized. >> 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. > > EAGAIN does seem better unless the message is too big to ever fit > in the kfifo. > >> if (retval != required ) { >> dev_dbg(device->dev, "write to fifo failed, reason unknown, non recoverable."); >> return -EAGAIN; >> } > > Maybe this should be dev_warn or even dev_crit if the driver is not > usable anymore when this happens? The error message should than also > be adjusted to EBADF or something similar. From my point of veiew, the warning is (in combination of the size-check) the by far better solution then the fifo reset. So all in all, I think, we should go with your proposal. Unfortunaly still no time to setup my test environment with a current version of the driver in order to give it a try :-( Sorry, Marcus