2020-09-25 22:39:05

by Tobias Jordan

[permalink] [raw]
Subject: [PATCH] drm: of: fix leak of port_node

The for_each_child_of_node loop in drm_of_lvds_get_remote_pixels_type
bails out in two occasions. Originally, both were calling of_node_put to
clean up, but (probably a typo) for the wrong variable.

One of these typos was fixed in commit 4ee48cc5586b ("drm: of: Fix
double-free bug"), but that missed the leak of the original port_node
and also the first error path which was obviously wrong as well.

Fix the leak of port_node in the error paths by calling of_node_put on
it.

Fixes: 6529007522de ("drm: of: Add drm_of_lvds_get_dual_link_pixel_order")
Signed-off-by: Tobias Jordan <[email protected]>
---
drivers/gpu/drm/drm_of.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
index ca04c34e8251..5c136bd5a671 100644
--- a/drivers/gpu/drm/drm_of.c
+++ b/drivers/gpu/drm/drm_of.c
@@ -315,7 +315,7 @@ static int drm_of_lvds_get_remote_pixels_type(

remote_port = of_graph_get_remote_port(endpoint);
if (!remote_port) {
- of_node_put(remote_port);
+ of_node_put(port_node);
return -EPIPE;
}

@@ -331,8 +331,10 @@ static int drm_of_lvds_get_remote_pixels_type(
* configurations by passing the endpoints explicitly to
* drm_of_lvds_get_dual_link_pixel_order().
*/
- if (!current_pt || pixels_type != current_pt)
+ if (!current_pt || pixels_type != current_pt) {
+ of_node_put(port_node);
return -EINVAL;
+ }
}

return pixels_type;
--
2.20.1


2020-09-26 01:59:16

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] drm: of: fix leak of port_node

Hi Tobias,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.9-rc6 next-20200925]
[cannot apply to drm/drm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Tobias-Jordan/drm-of-fix-leak-of-port_node/20200926-063854
base: git://anongit.freedesktop.org/drm-intel for-linux-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9acba5320ef136e5d4a3b7563f4b5a362922c818
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tobias-Jordan/drm-of-fix-leak-of-port_node/20200926-063854
git checkout 9acba5320ef136e5d4a3b7563f4b5a362922c818
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=xtensa

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

drivers/gpu/drm/drm_of.c: In function 'drm_of_lvds_get_remote_pixels_type':
>> drivers/gpu/drm/drm_of.c:318:16: warning: passing argument 1 of 'of_node_put' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
318 | of_node_put(port_node);
| ^~~~~~~~~
In file included from include/linux/irqdomain.h:35,
from include/linux/acpi.h:13,
from include/linux/i2c.h:13,
from include/drm/drm_crtc.h:28,
from include/drm/drm_atomic.h:31,
from include/drm/drm_bridge.h:30,
from drivers/gpu/drm/drm_of.c:7:
include/linux/of.h:122:45: note: expected 'struct device_node *' but argument is of type 'const struct device_node *'
122 | extern void of_node_put(struct device_node *node);
| ~~~~~~~~~~~~~~~~~~~~^~~~
drivers/gpu/drm/drm_of.c:335:16: warning: passing argument 1 of 'of_node_put' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
335 | of_node_put(port_node);
| ^~~~~~~~~
In file included from include/linux/irqdomain.h:35,
from include/linux/acpi.h:13,
from include/linux/i2c.h:13,
from include/drm/drm_crtc.h:28,
from include/drm/drm_atomic.h:31,
from include/drm/drm_bridge.h:30,
from drivers/gpu/drm/drm_of.c:7:
include/linux/of.h:122:45: note: expected 'struct device_node *' but argument is of type 'const struct device_node *'
122 | extern void of_node_put(struct device_node *node);
| ~~~~~~~~~~~~~~~~~~~~^~~~

vim +318 drivers/gpu/drm/drm_of.c

302
303 static int drm_of_lvds_get_remote_pixels_type(
304 const struct device_node *port_node)
305 {
306 struct device_node *endpoint = NULL;
307 int pixels_type = -EPIPE;
308
309 for_each_child_of_node(port_node, endpoint) {
310 struct device_node *remote_port;
311 int current_pt;
312
313 if (!of_node_name_eq(endpoint, "endpoint"))
314 continue;
315
316 remote_port = of_graph_get_remote_port(endpoint);
317 if (!remote_port) {
> 318 of_node_put(port_node);
319 return -EPIPE;
320 }
321
322 current_pt = drm_of_lvds_get_port_pixels_type(remote_port);
323 of_node_put(remote_port);
324 if (pixels_type < 0)
325 pixels_type = current_pt;
326
327 /*
328 * Sanity check, ensure that all remote endpoints have the same
329 * pixel type. We may lift this restriction later if we need to
330 * support multiple sinks with different dual-link
331 * configurations by passing the endpoints explicitly to
332 * drm_of_lvds_get_dual_link_pixel_order().
333 */
334 if (!current_pt || pixels_type != current_pt) {
335 of_node_put(port_node);
336 return -EINVAL;
337 }
338 }
339
340 return pixels_type;
341 }
342

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (4.73 kB)
.config.gz (63.60 kB)
Download all attachments

2020-09-26 19:27:14

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] drm: of: fix leak of port_node

Hi Tobias,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.9-rc6 next-20200925]
[cannot apply to drm/drm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Tobias-Jordan/drm-of-fix-leak-of-port_node/20200926-063854
base: git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-s001-20200925 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.2-201-g24bdaac6-dirty
# https://github.com/0day-ci/linux/commit/9acba5320ef136e5d4a3b7563f4b5a362922c818
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tobias-Jordan/drm-of-fix-leak-of-port_node/20200926-063854
git checkout 9acba5320ef136e5d4a3b7563f4b5a362922c818
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)

>> drivers/gpu/drm/drm_of.c:318:37: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected struct device_node *node @@ got struct device_node const *port_node @@
>> drivers/gpu/drm/drm_of.c:318:37: sparse: expected struct device_node *node
>> drivers/gpu/drm/drm_of.c:318:37: sparse: got struct device_node const *port_node
drivers/gpu/drm/drm_of.c:335:37: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected struct device_node *node @@ got struct device_node const *port_node @@
drivers/gpu/drm/drm_of.c:335:37: sparse: expected struct device_node *node
drivers/gpu/drm/drm_of.c:335:37: sparse: got struct device_node const *port_node

vim +318 drivers/gpu/drm/drm_of.c

302
303 static int drm_of_lvds_get_remote_pixels_type(
304 const struct device_node *port_node)
305 {
306 struct device_node *endpoint = NULL;
307 int pixels_type = -EPIPE;
308
309 for_each_child_of_node(port_node, endpoint) {
310 struct device_node *remote_port;
311 int current_pt;
312
313 if (!of_node_name_eq(endpoint, "endpoint"))
314 continue;
315
316 remote_port = of_graph_get_remote_port(endpoint);
317 if (!remote_port) {
> 318 of_node_put(port_node);
319 return -EPIPE;
320 }
321
322 current_pt = drm_of_lvds_get_port_pixels_type(remote_port);
323 of_node_put(remote_port);
324 if (pixels_type < 0)
325 pixels_type = current_pt;
326
327 /*
328 * Sanity check, ensure that all remote endpoints have the same
329 * pixel type. We may lift this restriction later if we need to
330 * support multiple sinks with different dual-link
331 * configurations by passing the endpoints explicitly to
332 * drm_of_lvds_get_dual_link_pixel_order().
333 */
334 if (!current_pt || pixels_type != current_pt) {
335 of_node_put(port_node);
336 return -EINVAL;
337 }
338 }
339
340 return pixels_type;
341 }
342

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (3.63 kB)
.config.gz (36.40 kB)
Download all attachments