From: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: gregkh@linuxfoundation.org, realwakka@gmail.com,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: pi433: enforce tx_cfg to be set before any message can be sent
Date: Wed, 12 Jan 2022 21:40:02 +1300 [thread overview]
Message-ID: <20220112084002.GA27596@mail.google.com> (raw)
In-Reply-To: <20220110091723.GB1951@kadam>
On Mon, Jan 10, 2022 at 12:17:23PM +0300, Dan Carpenter wrote:
> Seems reasonable.
>
> On Sun, Jan 09, 2022 at 11:26:52AM +1300, Paulo Miguel Almeida wrote:
> > meta-comments:
> > - I'm not entirely sure if -EPERM is the best error code to return here,
> > I'm taking suggestions
>
> Better to just return -EINVAL.
> > ---
> > drivers/staging/pi433/pi433_if.c | 16 +++++++++++++++-
> > 1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
> > index 051c9052aeeb..3e9913f4bc7d 100644
> > --- a/drivers/staging/pi433/pi433_if.c
> > +++ b/drivers/staging/pi433/pi433_if.c
> > @@ -108,6 +108,9 @@ struct pi433_device {
> > struct pi433_instance {
> > struct pi433_device *device;
> > struct pi433_tx_cfg tx_cfg;
> > +
> > + /* control flags */
> > + bool tx_cfg_initialized;
> > };
> >
> > /*-------------------------------------------------------------------------*/
> > @@ -823,6 +826,16 @@ pi433_write(struct file *filp, const char __user *buf,
> > if (count > MAX_MSG_SIZE)
> > return -EMSGSIZE;
> >
> > + /*
> > + * check if tx_cfg has been initialized otherwise we won't be able to
> > + * config the RF trasmitter correctly due to invalid settings
> > + */
> > + if (!instance->tx_cfg_initialized) {
> > + dev_dbg(device->dev,
> > + "write: failed due to uninitialized tx_cfg");
>
> Use dev_notice_once() or similar. Maybe "unconfigured" instead of
> uninitialized?
>
> dev_notice_once(device->dev,
> "write: failed due to unconfigured tx_cfg (see PI433_IOC_WR_TX_CFG)");
>
>
> > + return -EPERM;
> > + }
> > +
> > /*
> > * write the following sequence into fifo:
> > * - tx_cfg
> > @@ -897,6 +910,7 @@ pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> > return -EFAULT;
> > mutex_lock(&device->tx_fifo_lock);
> > memcpy(&instance->tx_cfg, &tx_cfg, sizeof(struct pi433_tx_cfg));
> > + instance->tx_cfg_initialized = true;
> > mutex_unlock(&device->tx_fifo_lock);
> > break;
> > case PI433_IOC_RD_RX_CFG:
> > @@ -950,7 +964,7 @@ static int pi433_open(struct inode *inode, struct file *filp)
> > /* setup instance data*/
> > instance->device = device;
> > instance->tx_cfg.bit_rate = 4711;
>
> This is sort of pointless because it can't work until that gets over
> written.
>
>
> > - // TODO: fill instance->tx_cfg;
> > + instance->tx_cfg_initialized = false;
>
> kzalloc() will already set this to false.
>
> regards,
> dan carpenter
>
I agree with you on all points mentioned above. I will send another
version of this patch shortly.
Thanks for the patch review.
Paulo A.
next prev parent reply other threads:[~2022-01-12 8:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-08 22:26 [PATCH] staging: pi433: enforce tx_cfg to be set before any message can be sent Paulo Miguel Almeida
2022-01-09 15:49 ` Sidong Yang
2022-01-09 19:05 ` Paulo Miguel Almeida
2022-01-10 14:05 ` Sidong Yang
2022-01-10 9:17 ` Dan Carpenter
2022-01-12 8:40 ` Paulo Miguel Almeida [this message]
2022-01-14 22:16 ` [PATCH v2] " Paulo Miguel Almeida
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=20220112084002.GA27596@mail.google.com \
--to=paulo.miguel.almeida.rodenas@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=realwakka@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).