diff mbox

drm/exynos: fix pages allocation in lowlevel_buffer_allocate

Message ID 1372762762-15480-1-git-send-email-sw0312.kim@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Seung-Woo Kim July 2, 2013, 10:59 a.m. UTC
From: YoungJun Cho <yj44.cho@samsung.com>

When drm iommu is not supported, buf->pages has to be allocated
and assigned to phys_to_page() result, which type is struct page *.
So it is sufficient to allocate buf->pages with multiple struct
page pointer size.

Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_buf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ville Syrjala July 2, 2013, 11:36 a.m. UTC | #1
On Tue, Jul 02, 2013 at 07:59:22PM +0900, Seung-Woo Kim wrote:
> From: YoungJun Cho <yj44.cho@samsung.com>
> 
> When drm iommu is not supported, buf->pages has to be allocated
> and assigned to phys_to_page() result, which type is struct page *.
> So it is sufficient to allocate buf->pages with multiple struct
> page pointer size.
> 
> Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> ---
>  drivers/gpu/drm/exynos/exynos_drm_buf.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c
> index 22865ba..3200622 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
> @@ -57,7 +57,7 @@ static int lowlevel_buffer_allocate(struct drm_device *dev,
>  		dma_addr_t start_addr;
>  		unsigned int i = 0;
>  
> -		buf->pages = kzalloc(sizeof(struct page) * nr_pages,
> +		buf->pages = kzalloc(sizeof(struct page *) * nr_pages,
>  					GFP_KERNEL);

Looks like a prime candidate for kcalloc()

>  		if (!buf->pages) {
>  			DRM_ERROR("failed to allocate pages.\n");
> -- 
> 1.7.9.5
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
YoungJun Cho July 2, 2013, 12:23 p.m. UTC | #2
Dear Ville

On Jul 2, 2013 8:42 PM, "Ville Syrjälä" <ville.syrjala@linux.intel.com>
wrote:
>
> On Tue, Jul 02, 2013 at 07:59:22PM +0900, Seung-Woo Kim wrote:
> > From: YoungJun Cho <yj44.cho@samsung.com>
> >
> > When drm iommu is not supported, buf->pages has to be allocated
> > and assigned to phys_to_page() result, which type is struct page *.
> > So it is sufficient to allocate buf->pages with multiple struct
> > page pointer size.
> >
> > Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
> > Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> > ---
> >  drivers/gpu/drm/exynos/exynos_drm_buf.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c
b/drivers/gpu/drm/exynos/exynos_drm_buf.c
> > index 22865ba..3200622 100644
> > --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
> > +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
> > @@ -57,7 +57,7 @@ static int lowlevel_buffer_allocate(struct drm_device
*dev,
> >               dma_addr_t start_addr;
> >               unsigned int i = 0;
> >
> > -             buf->pages = kzalloc(sizeof(struct page) * nr_pages,
> > +             buf->pages = kzalloc(sizeof(struct page *) * nr_pages,
> >                                       GFP_KERNEL);
>
> Looks like a prime candidate for kcalloc()
>

Thank you for nice comments.
I had no idea to consider overflow!

I'll update again.

Best regards YJ

> >               if (!buf->pages) {
> >                       DRM_ERROR("failed to allocate pages.\n");
> > --
> > 1.7.9.5
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/dri-devel
>
> --
> Ville Syrjälä
> Intel OTC
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
Inki Dae July 2, 2013, 12:41 p.m. UTC | #3
2013/7/2 YoungJun Cho <yj44.cho@samsung.com>:
> Dear Ville
>
> On Jul 2, 2013 8:42 PM, "Ville Syrjälä" <ville.syrjala@linux.intel.com>
> wrote:
>>
>> On Tue, Jul 02, 2013 at 07:59:22PM +0900, Seung-Woo Kim wrote:
>> > From: YoungJun Cho <yj44.cho@samsung.com>
>> >
>> > When drm iommu is not supported, buf->pages has to be allocated
>> > and assigned to phys_to_page() result, which type is struct page *.
>> > So it is sufficient to allocate buf->pages with multiple struct
>> > page pointer size.
>> >
>> > Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
>> > Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
>> > ---
>> >  drivers/gpu/drm/exynos/exynos_drm_buf.c |    2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c
>> > b/drivers/gpu/drm/exynos/exynos_drm_buf.c
>> > index 22865ba..3200622 100644
>> > --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
>> > +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
>> > @@ -57,7 +57,7 @@ static int lowlevel_buffer_allocate(struct drm_device
>> > *dev,
>> >               dma_addr_t start_addr;
>> >               unsigned int i = 0;
>> >
>> > -             buf->pages = kzalloc(sizeof(struct page) * nr_pages,
>> > +             buf->pages = kzalloc(sizeof(struct page *) * nr_pages,
>> >                                       GFP_KERNEL);
>>
>> Looks like a prime candidate for kcalloc()
>>
>
> Thank you for nice comments.
> I had no idea to consider overflow!
>
> I'll update again.

Mr. Cho,

it seems better to use utility function, drm_calloc_large().

Thanks,
Inki Dae

>
> Best regards YJ
>
>> >               if (!buf->pages) {
>> >                       DRM_ERROR("failed to allocate pages.\n");
>> > --
>> > 1.7.9.5
>> >
>> > _______________________________________________
>> > dri-devel mailing list
>> > dri-devel@lists.freedesktop.org
>> > http://lists.freedesktop.org/mailman/listinfo/dri-devel
>>
>> --
>> Ville Syrjälä
>> Intel OTC
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>
YoungJun Cho July 3, 2013, 12:07 a.m. UTC | #4
Dear Mr.Dae,

On Jul 2, 2013 9:42 PM, "Inki Dae" <inki.dae@samsung.com> wrote:
>
> 2013/7/2 YoungJun Cho <yj44.cho@samsung.com>:
> > Dear Ville
> >
> > On Jul 2, 2013 8:42 PM, "Ville Syrjälä" <ville.syrjala@linux.intel.com>
> > wrote:
> >>
> >> On Tue, Jul 02, 2013 at 07:59:22PM +0900, Seung-Woo Kim wrote:
> >> > From: YoungJun Cho <yj44.cho@samsung.com>
> >> >
> >> > When drm iommu is not supported, buf->pages has to be allocated
> >> > and assigned to phys_to_page() result, which type is struct page *.
> >> > So it is sufficient to allocate buf->pages with multiple struct
> >> > page pointer size.
> >> >
> >> > Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
> >> > Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> >> > ---
> >> >  drivers/gpu/drm/exynos/exynos_drm_buf.c |    2 +-
> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c
> >> > b/drivers/gpu/drm/exynos/exynos_drm_buf.c
> >> > index 22865ba..3200622 100644
> >> > --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
> >> > +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
> >> > @@ -57,7 +57,7 @@ static int lowlevel_buffer_allocate(struct
drm_device
> >> > *dev,
> >> >               dma_addr_t start_addr;
> >> >               unsigned int i = 0;
> >> >
> >> > -             buf->pages = kzalloc(sizeof(struct page) * nr_pages,
> >> > +             buf->pages = kzalloc(sizeof(struct page *) * nr_pages,
> >> >                                       GFP_KERNEL);
> >>
> >> Looks like a prime candidate for kcalloc()
> >>
> >
> > Thank you for nice comments.
> > I had no idea to consider overflow!
> >
> > I'll update again.
>
> Mr. Cho,
>
> it seems better to use utility function, drm_calloc_large().
>

Your comment is more suitable for this patch. I'll use it.

Thank you!

Best regards YJ

> Thanks,
> Inki Dae
>
> >
> > Best regards YJ
> >
> >> >               if (!buf->pages) {
> >> >                       DRM_ERROR("failed to allocate pages.\n");
> >> > --
> >> > 1.7.9.5
> >> >
> >> > _______________________________________________
> >> > dri-devel mailing list
> >> > dri-devel@lists.freedesktop.org
> >> > http://lists.freedesktop.org/mailman/listinfo/dri-devel
> >>
> >> --
> >> Ville Syrjälä
> >> Intel OTC
> >> _______________________________________________
> >> dri-devel mailing list
> >> dri-devel@lists.freedesktop.org
> >> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> >
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/dri-devel
> >
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c
index 22865ba..3200622 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
@@ -57,7 +57,7 @@  static int lowlevel_buffer_allocate(struct drm_device *dev,
 		dma_addr_t start_addr;
 		unsigned int i = 0;
 
-		buf->pages = kzalloc(sizeof(struct page) * nr_pages,
+		buf->pages = kzalloc(sizeof(struct page *) * nr_pages,
 					GFP_KERNEL);
 		if (!buf->pages) {
 			DRM_ERROR("failed to allocate pages.\n");