diff mbox

[1/2] iommu/omap: Check for valid archdata in attach_dev

Message ID 1409788712-10741-2-git-send-email-s-anna@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Suman Anna Sept. 3, 2014, 11:58 p.m. UTC
Any device requiring to be attached to an iommu_domain must have
valid archdata containing the necessary iommu information, which
is SoC-specific. Add a check in the omap_iommu_attach_dev to make
sure that the device has non-NULL archdata before accessing
different SoC-specific fields of the archdata. This prevents a
NULL pointer dereference on any misconfigured devices.

Signed-off-by: Suman Anna <s-anna@ti.com>
---
 drivers/iommu/omap-iommu.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Laurent Pinchart Sept. 4, 2014, 7:11 a.m. UTC | #1
Hi Suman,

Thank you for the patch.

On Wednesday 03 September 2014 18:58:31 Suman Anna wrote:
> Any device requiring to be attached to an iommu_domain must have
> valid archdata containing the necessary iommu information, which
> is SoC-specific. Add a check in the omap_iommu_attach_dev to make
> sure that the device has non-NULL archdata before accessing
> different SoC-specific fields of the archdata. This prevents a
> NULL pointer dereference on any misconfigured devices.
> 
> Signed-off-by: Suman Anna <s-anna@ti.com>
> ---
>  drivers/iommu/omap-iommu.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
> index 02ef0ac..f245d51 100644
> --- a/drivers/iommu/omap-iommu.c
> +++ b/drivers/iommu/omap-iommu.c
> @@ -1092,6 +1092,12 @@ omap_iommu_attach_dev(struct iommu_domain *domain,
> struct device *dev)
> 
>  	spin_lock(&omap_domain->lock);
> 
> +	if (!arch_data) {
> +		dev_err(dev, "device doesn't have an associated iommu\n");
> +		ret = -EINVAL;
> +		goto out;
> +	}

You can move this check outside of the spinlock-protected section. With that 
change,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +
>  	/* only a single device is supported per domain for now */
>  	if (omap_domain->iommu_dev) {
>  		dev_err(dev, "iommu domain is already attached\n");
Suman Anna Sept. 4, 2014, 7:37 p.m. UTC | #2
Hi Laurent,

> On Wednesday 03 September 2014 18:58:31 Suman Anna wrote:
>> Any device requiring to be attached to an iommu_domain must have
>> valid archdata containing the necessary iommu information, which
>> is SoC-specific. Add a check in the omap_iommu_attach_dev to make
>> sure that the device has non-NULL archdata before accessing
>> different SoC-specific fields of the archdata. This prevents a
>> NULL pointer dereference on any misconfigured devices.
>>
>> Signed-off-by: Suman Anna <s-anna@ti.com>
>> ---
>>  drivers/iommu/omap-iommu.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
>> index 02ef0ac..f245d51 100644
>> --- a/drivers/iommu/omap-iommu.c
>> +++ b/drivers/iommu/omap-iommu.c
>> @@ -1092,6 +1092,12 @@ omap_iommu_attach_dev(struct iommu_domain *domain,
>> struct device *dev)
>>
>>  	spin_lock(&omap_domain->lock);
>>
>> +	if (!arch_data) {
>> +		dev_err(dev, "device doesn't have an associated iommu\n");
>> +		ret = -EINVAL;
>> +		goto out;
>> +	}
> 
> You can move this check outside of the spinlock-protected section. With that 
> change,

Thanks, will fix this in the next revision, will also add the check for
the name field.

regards
Suman

> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
>> +
>>  	/* only a single device is supported per domain for now */
>>  	if (omap_domain->iommu_dev) {
>>  		dev_err(dev, "iommu domain is already attached\n");
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 02ef0ac..f245d51 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1092,6 +1092,12 @@  omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 
 	spin_lock(&omap_domain->lock);
 
+	if (!arch_data) {
+		dev_err(dev, "device doesn't have an associated iommu\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
 	/* only a single device is supported per domain for now */
 	if (omap_domain->iommu_dev) {
 		dev_err(dev, "iommu domain is already attached\n");