From: Marcus Wolf <marcus.wolf@smarthome-wolf.de>
To: Valentin Vidic <Valentin.Vidic@CARNet.hr>,
Marcus Wolf <marcus.wolf@smarthome-wolf.de>
Cc: devel@driverdev.osuosl.org, "Derek Robson" <robsonde@gmail.com>,
"Michael Panzlaff" <michael.panzlaff@fau.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Luca Söthe" <luca@acul.me>,
linux-kernel@vger.kernel.org,
"Marcin Ciupak" <marcin.s.ciupak@gmail.com>,
"Marcus Wolf" <linux@Wolf-Entwicklungen.de>,
"Simon Sandström" <simon@nikanor.nu>
Subject: Re: [PATCH] staging: pi433: add descriptions for mutex locks
Date: Sun, 8 Apr 2018 17:22:46 +0200 [thread overview]
Message-ID: <68bb0145-b144-b442-7ff3-c6080e44f377@smarthome-wolf.de> (raw)
In-Reply-To: <20180325130944.GU31333@gavran.carpriv.carnet.hr>
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 :)
>
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
next prev parent reply other threads:[~2018-04-08 15:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 9:47 Valentin Vidic
2018-03-23 10:22 ` Marcus Wolf
2018-03-23 11:42 ` Valentin Vidic
2018-03-23 15:38 ` Marcus Wolf
2018-03-23 18:00 ` Valentin Vidic
2018-03-23 22:18 ` Valentin Vidic
2018-03-24 22:09 ` [PATCH] staging: pi433: cleanup tx_fifo locking Valentin Vidic
2018-03-25 13:00 ` [PATCH] staging: pi433: add descriptions for mutex locks Marcus Wolf
2018-03-25 13:09 ` Valentin Vidic
2018-03-25 13:12 ` Marcus Wolf
2018-03-25 14:24 ` Valentin Vidic
2018-04-08 14:15 ` Marcus Wolf
2018-04-12 17:15 ` Valentin Vidic
2018-04-19 9:25 ` Marcus Wolf
2018-04-19 9:47 ` Valentin Vidic
2018-04-19 9:55 ` Marcus Wolf
2018-04-08 15:22 ` Marcus Wolf [this message]
2018-04-12 18:46 ` Valentin Vidic
2018-04-19 9:33 ` Marcus Wolf
2018-04-19 10:25 ` [PATCH v2] staging: pi433: cleanup tx_fifo locking Valentin Vidic
2018-04-19 10:40 ` Marcus Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68bb0145-b144-b442-7ff3-c6080e44f377@smarthome-wolf.de \
--to=marcus.wolf@smarthome-wolf.de \
--cc=Valentin.Vidic@CARNet.hr \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@Wolf-Entwicklungen.de \
--cc=luca@acul.me \
--cc=marcin.s.ciupak@gmail.com \
--cc=michael.panzlaff@fau.de \
--cc=robsonde@gmail.com \
--cc=simon@nikanor.nu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®