Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751524AbbLIPcY (ORCPT ); Wed, 9 Dec 2015 10:32:24 -0500 Received: from mga03.intel.com ([134.134.136.65]:47055 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751183AbbLIPcW (ORCPT ); Wed, 9 Dec 2015 10:32:22 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,404,1444719600"; d="scan'208";a="870085563" From: Jani Nikula To: LABBE Corentin , airlied@linux.ie Cc: LABBE Corentin , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH v2 1/1] drm: modes: fix DRM modes analysis regression In-Reply-To: <1449667811-24472-2-git-send-email-clabbe.montjoie@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <1449667811-24472-1-git-send-email-clabbe.montjoie@gmail.com> <1449667811-24472-2-git-send-email-clabbe.montjoie@gmail.com> User-Agent: Notmuch/0.20.2+101~gb57168b (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Wed, 09 Dec 2015 17:32:05 +0200 Message-ID: <871tavwscq.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4096 Lines: 128 On Wed, 09 Dec 2015, LABBE Corentin wrote: > My latest commit introduce some case where a valid mode, could be > rejected. > simple_strtox functions stop at first non-digit character, but kstrtox not. > So args like "video=HDMI-A-1:720x480-16@60" will be reject when checking 16@. > The proper solution is to store digits in a specific buffer. Or to revert regressing commit...? Your original commit complicated the already complicated function, and this one makes it more so. What is the benefit? > Fixes: 52157a4ca396 ("drm: modes: replace simple_strtoul by kstrtouint") For me the commit id is cc344980c76748e57c9c03100c2a14d36ab00334. BR, Jani. > Reported-by: Kuninori Morimoto > Signed-off-by: LABBE Corentin > --- > drivers/gpu/drm/drm_modes.c | 28 +++++++++++++++++++++------- > 1 file changed, 21 insertions(+), 7 deletions(-) > > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c > index bde9b29..da1e80d 100644 > --- a/drivers/gpu/drm/drm_modes.c > +++ b/drivers/gpu/drm/drm_modes.c > @@ -1225,13 +1225,14 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, > struct drm_cmdline_mode *mode) > { > const char *name; > - unsigned int namelen; > + unsigned int namelen, digit_i; > bool res_specified = false, bpp_specified = false, refresh_specified = false; > unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0; > bool yres_specified = false, cvt = false, rb = false; > bool interlace = false, margins = false, was_digit = false; > int i, err; > enum drm_connector_force force = DRM_FORCE_UNSPECIFIED; > + char *digits; > > #ifdef CONFIG_FB > if (!mode_option) > @@ -1245,42 +1246,53 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, > > name = mode_option; > namelen = strlen(name); > + > + digits = kzalloc(namelen, GFP_KERNEL); > + if (!digits) > + return false; > + /* The last character must be the last 0 */ > + digit_i = namelen; > + > for (i = namelen-1; i >= 0; i--) { > switch (name[i]) { > case '@': > if (!refresh_specified && !bpp_specified && > !yres_specified && !cvt && !rb && was_digit) { > - err = kstrtouint(&name[i + 1], 10, &refresh); > + err = kstrtouint(&digits[digit_i], 10, &refresh); > if (err) > - return false; > + goto done; > refresh_specified = true; > was_digit = false; > + digit_i = namelen; > } else > goto done; > break; > case '-': > if (!bpp_specified && !yres_specified && !cvt && > !rb && was_digit) { > - err = kstrtouint(&name[i + 1], 10, &bpp); > + err = kstrtouint(&digits[digit_i], 10, &bpp); > if (err) > - return false; > + goto done; > bpp_specified = true; > was_digit = false; > + digit_i = namelen; > } else > goto done; > break; > case 'x': > if (!yres_specified && was_digit) { > - err = kstrtouint(&name[i + 1], 10, &yres); > + err = kstrtouint(&digits[digit_i], 10, &yres); > if (err) > - return false; > + goto done; > yres_specified = true; > was_digit = false; > + digit_i = namelen; > } else > goto done; > break; > case '0' ... '9': > was_digit = true; > + digits[--digit_i] = name[i]; > break; > case 'M': > if (yres_specified || cvt || was_digit) > @@ -1349,6 +1361,7 @@ done: > "parse error at position %i in video mode '%s'\n", > i, name); > mode->specified = false; > + kfree(digits); > return false; > } > > @@ -1373,6 +1386,7 @@ done: > mode->margins = margins; > mode->force = force; > > + kfree(digits); > return true; > } > EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector); -- Jani Nikula, Intel Open Source Technology Center -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/