[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZGfPME8zrxfJ+f8E@Asurada-Nvidia>
Date: Fri, 19 May 2023 12:34:08 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: "Liu, Jingqi" <jingqi.liu@...el.com>
CC: Yi Liu <yi.l.liu@...el.com>, <joro@...tes.org>,
<alex.williamson@...hat.com>, <jgg@...dia.com>,
<kevin.tian@...el.com>, <robin.murphy@....com>,
<baolu.lu@...ux.intel.com>, <cohuck@...hat.com>,
<eric.auger@...hat.com>, <kvm@...r.kernel.org>,
<mjrosato@...ux.ibm.com>, <chao.p.peng@...ux.intel.com>,
<yi.y.sun@...ux.intel.com>, <peterx@...hat.com>,
<jasowang@...hat.com>, <shameerali.kolothum.thodi@...wei.com>,
<lulu@...hat.com>, <suravee.suthikulpanit@....com>,
<iommu@...ts.linux.dev>, <linux-kernel@...r.kernel.org>,
<linux-kselftest@...r.kernel.org>, <zhenzhong.duan@...el.com>
Subject: Re: [PATCH v2 06/11] iommufd: IOMMU_HWPT_ALLOC allocation with user
data
On Wed, May 17, 2023 at 11:08:12AM +0800, Liu, Jingqi wrote:
> > + /*
> > + * All drivers support IOMMU_HWPT_TYPE_DEFAULT, so pass it through.
> > + * For any other hwpt_type, check the ops->domain_alloc_user_data_len
> > + * presence and its result.
> > + */
> > + if (cmd->hwpt_type != IOMMU_HWPT_TYPE_DEFAULT) {
> > + if (!ops->domain_alloc_user_data_len) {
> > + rc = -EOPNOTSUPP;
> > + goto out_put_idev;
> > + }
> > + klen = ops->domain_alloc_user_data_len(cmd->hwpt_type);
> > + if (WARN_ON(klen < 0)) {
> > + rc = -EINVAL;
> > + goto out_put_pt;
> > + }
> Would it be better if the later check "klen" is moved here ?
> if (klen) {
> [...]
> }
> If this check fails here, there's no need to execute the code after it.
> If this path is not executed, "klen" is 0, and there's no need to check it.
> Do I understand it right ?
Makes sense. And the klen value isn't really being used. So,
we may likely change it to a bool one. Also, I'm thinking of
forcing a !!cmd->data_len for a non-DEFAULT hwpt_type:
+ if (cmd->hwpt_type != IOMMU_HWPT_TYPE_DEFAULT) {
+ if (!cmd->data_len) {
+ rc = -EINVAL;
+ goto out_put_pt;
+ }
+ if (!ops->domain_alloc_user_data_len) {
+ rc = -EOPNOTSUPP;
+ goto out_put_pt;
+ }
+ if (!ops->hwpt_type_is_supported(cmd->hwpt_type)) {
+ rc = -EINVAL;
+ goto out_put_pt;
+ }
Then, for the latter part, simply:
+ if (cmd->data_len) {
+ // malloc data
+ }
Thanks
Nic
Powered by blists - more mailing lists