From: Viresh Kumar <viresh.kumar@linaro.org>
To: Jie Deng <jie.deng@intel.com>
Cc: linux-i2c@vger.kernel.org,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, wsa@kernel.org,
wsa+renesas@sang-engineering.com, mst@redhat.com, arnd@arndb.de,
jasowang@redhat.com, andriy.shevchenko@linux.intel.com,
yu1.wang@intel.com, shuo.a.liu@intel.com, conghui.chen@intel.com,
stefanha@redhat.com
Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver
Date: Mon, 5 Jul 2021 12:00:03 +0530 [thread overview]
Message-ID: <20210705063003.a45ic3wn74nre6xe@vireshk-i7> (raw)
In-Reply-To: <6aabc877-673a-e2bc-da2d-ec6741b4159b@intel.com>
On 05-07-21, 14:22, Jie Deng wrote:
> On 2021/7/5 12:38, Viresh Kumar wrote:
> > On 05-07-21, 11:45, Jie Deng wrote:
> > > On 2021/7/5 10:40, Viresh Kumar wrote:
> > > > On 02-07-21, 16:46, Jie Deng wrote:
> > > > The right way of doing this is is making this function return - Error on failure
> > > > and 0 on success. There is no point returning number of successful additions
> > > > here.
> > >
> > > We need the number for virtio_i2c_complete_reqs to do cleanup. We don't have
> > > to
> > >
> > > do cleanup "num" times every time. Just do it as needed.
> > If you do full cleanup here, then you won't required that at the caller site.
> >
> > > > Moreover, on failures this needs to clean up (free the dmabufs) itself, just
> > > > like you did i2c_put_dma_safe_msg_buf() at the end. The caller shouldn't be
> > > > required to handle the error cases by freeing up resources.
> > >
> > > This function will return the number of requests being successfully prepared
> > > and make sure
> > >
> > > resources of the failed request being freed. And virtio_i2c_complete_reqs
> > > will free the
> > >
> > > resources of those successful request.
> > It just looks cleaner to give such responsibility to each and every function,
> > i.e. if they fail, they should clean stuff up instead of the caller. That's the
> > normal philosophy you will find across kernel in most of the cases.
> > > > > + /*
> > > > > + * Condition (req && req == &reqs[i]) should always meet since
> > > > > + * we have total nr requests in the vq.
> > > > > + */
> > > > > + if (!failed && (WARN_ON(!(req && req == &reqs[i])) ||
> > > > > + (req->in_hdr.status != VIRTIO_I2C_MSG_OK)))
> > > > What about writing this as:
> > > >
> > > > if (!failed && (WARN_ON(req != &reqs[i]) ||
> > > > (req->in_hdr.status != VIRTIO_I2C_MSG_OK)))
> > > >
> > > > We don't need to check req here since if req is NULL, we will not do req->in_hdr
> > > > at all.
> > >
> > > It's right here just because the &reqs[i] will never be NULL in our case.
> > > But if you see
> > >
> > > "virtio_i2c_complete_reqs" as an independent function, you need to check the
> > >
> > > req. From the perspective of the callee, you can't ask the caller always
> > > give you
> > >
> > > the non-NULL parameters.
> > We need to keep this driver optimized in its current form. If you see your own
> > argument here, then why don't you test vq or msgs for a valid pointer ? And even
> > reqs.
> >
> > If we know for certain that this will never happen, then it should be optimized.
> > But if you see a case where reqs[i] can be NULL here, then it would be fine.
> > ot the driver. And we don't need to take care of that.
>
>
> This is still not enough to convince me. So I won't change them for now
> until I see it
>
> is the consensus of the majority.
Do you see reqs[i] to ever be NULL here ? If not, then if (req) is like if
(true).
Why would you want to have something like that ?
--
viresh
next prev parent reply other threads:[~2021-07-05 6:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-02 8:46 [PATCH v12] i2c: virtio: add a virtio i2c frontend driver Jie Deng
2021-07-02 9:58 ` Andy Shevchenko
2021-07-02 23:01 ` Wolfram Sang
2021-07-05 2:43 ` Viresh Kumar
2021-07-05 3:01 ` Jie Deng
2021-07-05 6:21 ` Jie Deng
2021-07-05 6:31 ` Viresh Kumar
2021-07-05 3:46 ` Jie Deng
2021-07-05 2:40 ` Viresh Kumar
2021-07-05 3:45 ` Jie Deng
2021-07-05 4:38 ` Viresh Kumar
2021-07-05 6:22 ` Jie Deng
2021-07-05 6:30 ` Viresh Kumar [this message]
2021-07-05 7:13 ` Jie Deng
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=20210705063003.a45ic3wn74nre6xe@vireshk-i7 \
--to=viresh.kumar@linaro.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=conghui.chen@intel.com \
--cc=jasowang@redhat.com \
--cc=jie.deng@intel.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=shuo.a.liu@intel.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=wsa@kernel.org \
--cc=yu1.wang@intel.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).