Commit 5ff32f69e75deca5ee1a2f421ca8a3e43cfaa339

Authored by Florian Tobias Schandinat
Committed by Linus Torvalds
1 parent 837b0abba1

viafb: use read-only mode parsing

viafb: use read-only mode parsing

The previous method of mode parsing wrote to the strings resulting in
truncated mode strings in the sysfs.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Cc: Scott Fang <ScottFang@viatech.com.cn>
Cc: Joseph Chan <JosephChan@via.com.tw>
Cc: Harald Welte <laforge@gnumonks.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 25 additions and 19 deletions Side-by-side Diff

drivers/video/via/viafbdev.c
... ... @@ -1821,11 +1821,29 @@
1821 1821 remove_proc_entry("viafb", NULL);
1822 1822 }
1823 1823  
  1824 +static void parse_mode(const char *str, u32 *xres, u32 *yres)
  1825 +{
  1826 + char *ptr;
  1827 +
  1828 + *xres = simple_strtoul(str, &ptr, 10);
  1829 + if (ptr[0] != 'x')
  1830 + goto out_default;
  1831 +
  1832 + *yres = simple_strtoul(&ptr[1], &ptr, 10);
  1833 + if (ptr[0])
  1834 + goto out_default;
  1835 +
  1836 + return;
  1837 +
  1838 +out_default:
  1839 + printk(KERN_WARNING "viafb received invalid mode string: %s\n", str);
  1840 + *xres = 640;
  1841 + *yres = 480;
  1842 +}
  1843 +
1824 1844 static int __devinit via_pci_probe(void)
1825 1845 {
1826   - unsigned long default_xres, default_yres;
1827   - char *tmpc, *tmpm;
1828   - char *tmpc_sec, *tmpm_sec;
  1846 + u32 default_xres, default_yres;
1829 1847 int vmode_index;
1830 1848 u32 viafb_par_length;
1831 1849  
1832 1850  
... ... @@ -1902,26 +1920,14 @@
1902 1920 viafb_second_size * 1024 * 1024;
1903 1921 }
1904 1922  
1905   - tmpm = viafb_mode;
1906   - tmpc = strsep(&tmpm, "x");
1907   - strict_strtoul(tmpc, 0, &default_xres);
1908   - strict_strtoul(tmpm, 0, &default_yres);
1909   -
  1923 + parse_mode(viafb_mode, &default_xres, &default_yres);
1910 1924 vmode_index = viafb_get_mode_index(default_xres, default_yres);
1911 1925 DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index);
1912 1926  
1913 1927 if (viafb_SAMM_ON == 1) {
1914   - if (strcmp(viafb_mode, viafb_mode1)) {
1915   - tmpm_sec = viafb_mode1;
1916   - tmpc_sec = strsep(&tmpm_sec, "x");
1917   - strict_strtoul(tmpc_sec, 0,
1918   - (unsigned long *)&viafb_second_xres);
1919   - strict_strtoul(tmpm_sec, 0,
1920   - (unsigned long *)&viafb_second_yres);
1921   - } else {
1922   - viafb_second_xres = default_xres;
1923   - viafb_second_yres = default_yres;
1924   - }
  1928 + parse_mode(viafb_mode1, &viafb_second_xres,
  1929 + &viafb_second_yres);
  1930 +
1925 1931 if (0 == viafb_second_virtual_xres) {
1926 1932 switch (viafb_second_xres) {
1927 1933 case 1400: