[PATCH] drm/amd/display: Fix error code on failure to set brightness

2021-06-08 Thread Anand K Mistry
The backlight_ops.update_status function is required to return a
negative error code on failure. Returning a positive code may be
interpreted as a success. This is true for the 'brightness' sysfs file,
which passes through a non-zero value as the return value of the write()
syscall. This is interpreted in user-space as a successful write of 1
character, which is obviously wrong.

It's not clear exactly what error code to use, but EINVAL should be
reasonable.

Signed-off-by: Anand K Mistry 
---

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 652cc1a0e450..ad322613390d 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3431,7 +3431,7 @@ static int amdgpu_dm_backlight_update_status(struct 
backlight_device *bd)
else
rc = dc_link_set_backlight_level(dm->backlight_link, 
brightness, 0);
 
-   return rc ? 0 : 1;
+   return rc ? 0 : -EINVAL;
 }
 
 static int amdgpu_dm_backlight_get_brightness(struct backlight_device *bd)
-- 
2.32.0.rc1.229.g3e70b5a671-goog



Re: [PATCH] drm/mediatek: stop iterating dma addresses when sg_dma_len() == 0

2020-04-28 Thread Anand K. Mistry
On Sun, 26 Apr 2020 at 18:04, Chun-Kuang Hu  wrote:
>
> Hi, Anand:
>
> Anand K Mistry  於 2020年4月20日 週一 下午2:09寫道:
> >
> > If dma_map_sg() merges pages when creating the mapping, only the first
> > entries will have a valid sg_dma_address() and sg_dma_len(), followed by
> > entries with sg_dma_len() == 0.
> >
> > Signed-off-by: Anand K Mistry 
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_gem.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c 
> > b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> > index b04a3c2b111e09..f8fd8b98c30e3d 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> > @@ -224,6 +224,9 @@ struct drm_gem_object 
> > *mtk_gem_prime_import_sg_table(struct drm_device *dev,
> >
> > expected = sg_dma_address(sg->sgl);
> > for_each_sg(sg->sgl, s, sg->nents, i) {
> > +   if (!sg_dma_len(s))
> > +   break;
>
> I think this should be 'continue'

scatterlist.h has the comment:
/*
 * These macros should be used after a dma_map_sg call has been done
 * to get bus addresses of each of the SG entries and their lengths.
 * You should only work with the number of sg entries dma_map_sg
 * returns, or alternatively stop on the first sg_dma_len(sg) which
 * is 0.
 */

So breaking on the first sg_dma_len(sg) == 0 appears to be (one of)
the documented approach.

>
> Regards,
> Chun-Kuang.
>
> > +
> > if (sg_dma_address(s) != expected) {
> > DRM_ERROR("sg_table is not contiguous");
> > ret = -EINVAL;
> > --
> > 2.26.1.301.g55bc3eb7cb9-goog
> >
> >
> > ___
> > Linux-mediatek mailing list
> > linux-media...@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-mediatek
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm/mediatek: stop iterating dma addresses when sg_dma_len() == 0

2020-04-28 Thread Anand K. Mistry
On Sun, 26 Apr 2020 at 18:04, Chun-Kuang Hu  wrote:

> Hi, Anand:
>
> Anand K Mistry  於 2020年4月20日 週一 下午2:09寫道:
> >
> > If dma_map_sg() merges pages when creating the mapping, only the first
> > entries will have a valid sg_dma_address() and sg_dma_len(), followed by
> > entries with sg_dma_len() == 0.
> >
> > Signed-off-by: Anand K Mistry 
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_gem.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> > index b04a3c2b111e09..f8fd8b98c30e3d 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> > @@ -224,6 +224,9 @@ struct drm_gem_object
> *mtk_gem_prime_import_sg_table(struct drm_device *dev,
> >
> > expected = sg_dma_address(sg->sgl);
> > for_each_sg(sg->sgl, s, sg->nents, i) {
> > +   if (!sg_dma_len(s))
> > +   break;
>
> I think this should be 'continue'
>

scatterlist.h has the comment:
/*
 * These macros should be used after a dma_map_sg call has been done
 * to get bus addresses of each of the SG entries and their lengths.
 * You should only work with the number of sg entries dma_map_sg
 * returns, or alternatively stop on the first sg_dma_len(sg) which
 * is 0.
 */

So breaking on the first sg_dma_len(sg) == 0 appears to be (one of) the
documented approach.


> Regards,
> Chun-Kuang.
>
> > +
> > if (sg_dma_address(s) != expected) {
> > DRM_ERROR("sg_table is not contiguous");
> > ret = -EINVAL;
> > --
> > 2.26.1.301.g55bc3eb7cb9-goog
> >
> >
> > ___
> > Linux-mediatek mailing list
> > linux-media...@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-mediatek
>
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] drm/mediatek: stop iterating dma addresses when sg_dma_len() == 0

2020-04-19 Thread Anand K Mistry
If dma_map_sg() merges pages when creating the mapping, only the first
entries will have a valid sg_dma_address() and sg_dma_len(), followed by
entries with sg_dma_len() == 0.

Signed-off-by: Anand K Mistry 
---
 drivers/gpu/drm/mediatek/mtk_drm_gem.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c 
b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
index b04a3c2b111e09..f8fd8b98c30e3d 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
@@ -224,6 +224,9 @@ struct drm_gem_object *mtk_gem_prime_import_sg_table(struct 
drm_device *dev,
 
expected = sg_dma_address(sg->sgl);
for_each_sg(sg->sgl, s, sg->nents, i) {
+   if (!sg_dma_len(s))
+   break;
+
if (sg_dma_address(s) != expected) {
DRM_ERROR("sg_table is not contiguous");
ret = -EINVAL;
-- 
2.26.1.301.g55bc3eb7cb9-goog

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel