All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/99] fbdev: Fix memory leak in option parsing
@ 2023-03-06 15:58 ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Introduce struct option_iter and helpers to parse command-line
options with comma-separated key-value pairs. Then convert fbdev
drivers to the new interface. Fixes a memory leak in the parsing of
the video= option.

Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
caller; clarify ownership"), a call to fb_get_options() either
returned an internal string or a duplicated string; hence ownership of
the string's memory buffer was not well defined, but depended on how
users specified the video= option on the kernel command line. For
global settings, the caller owned the returned memory and for per-driver
settings, fb_get_options() owned the memory. As calling drivers were
unable to detect the case, the memory was leaked.

Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
clarify ownership") changed sematics to caller-owned strings. Drivers
still leaked the memory, but at least ownership was clear.

This patchset fixes the memory leak and changes string ownership back
to fb_get_options(). Patch 1 introduces struct option_iter and a few
helpers. The interface takes an option string, such as video=, in the
common form value1,key2:value2,value3 etc and returns the individial
comma-separated pairs. Various modules use this pattern, so the code
is located under lib/.

Patches 2 to 98 go through fbdev drivers and convert them to the new
interface. This often requires a number of cleanups. A driver would
typically refer to the option string's video mode. Such strings are now
copied to driver-allocated memory so that drivers don't refer directly
to the option string's memory. The option iterator then replaces manual
parsing loops based on strsep(",").

Patch 99 finally changes the ownership of the option string to be
internal to fb_get_option(); thereby fixing the memory leak. The option
iterator holds its own copy of the string and is not affected by the
change.

Most fbdev drivers only support to parse option strings if they are
built-in. I assume that's because of the original fuzzy semantics of
fb_get_options(). A later patchset could change the driver to respect
video= settings in any configuration.

Thomas Zimmermann (99):
  lib: Add option iterator
  fbdev/68328fb: Remove trailing whitespaces
  fbdev/68328fb: Remove unused option string
  fbdev/acornfb: Only init fb_info once
  fbdev/acornfb: Parse option string with struct option_iter
  fbdev/amifb: Duplicate video-mode option string
  fbdev/amifb: Parse option string with struct option_iter
  fbdev/arkfb: Duplicate video-mode option string
  fbdev/atafb: Duplicate video-mode option string
  fbdev/atafb: Parse option string with struct option_iter
  fbdev/aty: Duplicate video-mode option string
  fbdev/aty: Parse option string with struct option_iter
  fbdev/au1100fb: Parse option string with struct option_iter
  fbdev/au1200fb: Parse option string with struct option_iter
  fbdev/cirrusfb: Duplicate video-mode option string
  fbdev/cirrusfb: Parse option string with struct option_iter
  fbdev/controlfb: Remove trailing whitespaces
  fbdev/controlfb: Parse option string with struct option_iter
  fbdev/cyber2000fb: Parse option string with struct option_iter
  fbdev/efifb: Parse option string with struct option_iter
  fbdev/fm2fb: Parse option string with struct option_iter
  fbdev/fsl-diu-fb: Duplicate video-mode option string
  fbdev/fsl-diu-fb: Parse option string with struct option_iter
  fbdev/gbefb: Duplicate video-mode option string
  fbdev/gbefb: Parse option string with struct option_iter
  fbdev/geode: Duplicate video-mode option string
  fbdev/geode: Parse option string with struct option_iter
  fbdev/grvga: Duplicate video-mode option string
  fbdev/grvga: Parse option string with struct option_iter
  fbdev/gxt4500: Duplicate video-mode option string
  fbdev/hyperv_fb: Duplicate video-mode option string
  fbdev/i740fb: Duplicate video-mode option string
  fbdev/i740fb: Parse option string with struct option_iter
  fbdev/i810: Duplicate video-mode option string
  fbdev/i810: Parse option string with struct option_iter
  fbdev/imsttfb: Parse option string with struct option_iter
  fbdev/intelfb: Duplicate video-mode option string
  fbdev/intelfb: Parse option string with struct option_iter
  fbdev/imxfb: Duplicate video-mode option string
  fbdev/imxfb: Parse option string with struct option_iter
  fbdev/kyrofb: Duplicate video-mode option string
  fbdev/kyrofb: Parse option string with struct option_iter
  fbdev/macfb: Remove trailing whitespaces
  fbdev/macfb: Parse option string with struct option_iter
  fbdev/matroxfb: Parse option string with struct option_iter
  fbdev/mx3fb: Duplicate video-mode option string
  fbdev/mx3fb: Parse option string with struct option_iter
  fbdev/neofb: Duplicate video-mode option string
  fbdev/neofb: Parse option string with struct option_iter
  fbdev/nvidiafb: Duplicate video-mode option string
  fbdev/nvidiafb: Parse option string with struct option_iter
  fbdev/ocfb: Duplicate video-mode option string
  fbdev/ocfb: Parse option string with struct option_iter
  fbdev/omapfb: Parse option string with struct option_iter
  fbdev/platinumfb: Remove trailing whitespaces
  fbdev/platinumfb: Parse option string with struct option_iter
  fbdev/pm2fb: Duplicate video-mode option string
  fbdev/pm2fb: Parse option string with struct option_iter
  fbdev/pm3fb: Duplicate video-mode option string
  fbdev/pm3fb: Parse option string with struct option_iter
  fbdev/ps3fb: Duplicate video-mode option string
  fbdev/ps3fb: Parse option string with struct option_iter
  fbdev/pvr2fb: Duplicate video-mode option string
  fbdev/pvr2fb: Parse option string with struct option_iter
  fbdev/pxafb: Parse option string with struct option_iter
  fbdev/rivafb: Duplicate video-mode option string
  fbdev/rivafb: Parse option string with struct option_iter
  fbdev/s3fb: Duplicate video-mode option string
  fbdev/s3fb: Parse option string with struct option_iter
  fbdev/savagefb: Duplicate video-mode option string
  fbdev/savagefb: Parse option string with struct option_iter
  fbdev/sisfb: Constify mode string
  fbdev/sisfb: Parse option string with struct option_iter
  fbdev/skeletonfb: Parse option string with struct option_iter
  fbdev/sm712fb: Duplicate video-mode option string
  fbdev/sstfb: Duplicate video-mode option string
  fbdev/sstfb: Parse option string with struct option_iter
  fbdev/stifb: Remove trailing whitespaces
  fbdev/sti: Constify option string
  fbdev/tdfxfb: Duplicate video-mode option string
  fbdev/tdfxfb: Parse option string with struct option_iter
  fbdev/tgafb: Duplicate video-mode option string
  fbdev/tgafb: Parse option string with struct option_iter
  fbdev/tmiofb: Remove unused option string
  fbdev/tridentfb: Duplicate video-mode option string
  fbdev/tridentfb: Parse option string with struct option_iter
  fbdev/uvesafb: Duplicate video-mode option string
  fbdev/uvesafb: Parse option string with struct option_iter
  fbdev/valkyriefb: Remove trailing whitespaces
  fbdev/valkyriefb: Parse option string with struct option_iter
  fbdev/vermilion: Remove unused option string
  fbdev/vesafb: Parse option string with struct option_iter
  fbdev/vfb: Remove trailing whitespaces
  fbdev/vfb: Duplicate video-mode option string
  fbdev/vfb: Parse option string with struct option_iter
  fbdev/viafb: Parse option string with struct option_iter
  fbdev/vt8623fb: Duplicate video-mode option string
  staging/sm750fb: Parse option string with struct option_iter
  fbdev: Constify option strings

 Documentation/core-api/kernel-api.rst        |   9 ++
 drivers/staging/sm750fb/sm750.c              |  45 +++---
 drivers/video/fbdev/68328fb.c                |  24 +--
 drivers/video/fbdev/acornfb.c                |  25 ++-
 drivers/video/fbdev/amifb.c                  |  30 ++--
 drivers/video/fbdev/arkfb.c                  |  15 +-
 drivers/video/fbdev/atafb.c                  |  25 ++-
 drivers/video/fbdev/aty/aty128fb.c           |  28 +++-
 drivers/video/fbdev/aty/atyfb_base.c         |  29 +++-
 drivers/video/fbdev/aty/radeon_base.c        |  32 ++--
 drivers/video/fbdev/au1100fb.c               |  13 +-
 drivers/video/fbdev/au1200fb.c               |  15 +-
 drivers/video/fbdev/cirrusfb.c               |  37 +++--
 drivers/video/fbdev/controlfb.c              |  49 +++---
 drivers/video/fbdev/core/fb_cmdline.c        |  13 +-
 drivers/video/fbdev/core/modedb.c            |   8 +-
 drivers/video/fbdev/cyber2000fb.c            |  19 +--
 drivers/video/fbdev/efifb.c                  |  48 +++---
 drivers/video/fbdev/ep93xx-fb.c              |   2 +-
 drivers/video/fbdev/fm2fb.c                  |  16 +-
 drivers/video/fbdev/fsl-diu-fb.c             |  30 ++--
 drivers/video/fbdev/gbefb.c                  |  25 +--
 drivers/video/fbdev/geode/gx1fb_core.c       |  18 +--
 drivers/video/fbdev/geode/gxfb_core.c        |  25 +--
 drivers/video/fbdev/geode/lxfb_core.c        |  29 ++--
 drivers/video/fbdev/grvga.c                  |  32 +++-
 drivers/video/fbdev/gxt4500.c                |  18 ++-
 drivers/video/fbdev/hyperv_fb.c              |  18 ++-
 drivers/video/fbdev/i740fb.c                 |  32 ++--
 drivers/video/fbdev/i810/i810_main.c         |  30 +++-
 drivers/video/fbdev/imsttfb.c                |  18 ++-
 drivers/video/fbdev/imxfb.c                  |  23 ++-
 drivers/video/fbdev/intelfb/intelfbdrv.c     |  29 +++-
 drivers/video/fbdev/kyro/fbdev.c             |  27 ++--
 drivers/video/fbdev/macfb.c                  |  28 ++--
 drivers/video/fbdev/matrox/matroxfb_base.c   |  21 +--
 drivers/video/fbdev/mx3fb.c                  |  27 +++-
 drivers/video/fbdev/neofb.c                  |  32 ++--
 drivers/video/fbdev/nvidia/nvidia.c          |  32 ++--
 drivers/video/fbdev/ocfb.c                   |  25 ++-
 drivers/video/fbdev/omap/omapfb_main.c       |  15 +-
 drivers/video/fbdev/platinumfb.c             |  46 +++---
 drivers/video/fbdev/pm2fb.c                  |  31 ++--
 drivers/video/fbdev/pm3fb.c                  |  33 ++--
 drivers/video/fbdev/ps3fb.c                  |  32 ++--
 drivers/video/fbdev/pvr2fb.c                 |  29 ++--
 drivers/video/fbdev/pxafb.c                  |  20 ++-
 drivers/video/fbdev/riva/fbdev.c             |  32 ++--
 drivers/video/fbdev/s3fb.c                   |  33 ++--
 drivers/video/fbdev/savage/savagefb_driver.c |  26 ++-
 drivers/video/fbdev/sis/sis_main.c           |  26 +--
 drivers/video/fbdev/skeletonfb.c             |  17 +-
 drivers/video/fbdev/sm712fb.c                |  19 ++-
 drivers/video/fbdev/sstfb.c                  |  31 ++--
 drivers/video/fbdev/stifb.c                  | 162 +++++++++----------
 drivers/video/fbdev/tdfxfb.c                 |  27 ++--
 drivers/video/fbdev/tgafb.c                  |  35 ++--
 drivers/video/fbdev/tmiofb.c                 |  24 +--
 drivers/video/fbdev/tridentfb.c              |  33 ++--
 drivers/video/fbdev/uvesafb.c                |  27 ++--
 drivers/video/fbdev/valkyriefb.c             |  32 ++--
 drivers/video/fbdev/vermilion/vermilion.c    |   7 +-
 drivers/video/fbdev/vesafb.c                 |  18 ++-
 drivers/video/fbdev/vfb.c                    |  41 +++--
 drivers/video/fbdev/via/viafbdev.c           |  17 +-
 drivers/video/fbdev/vt8623fb.c               |  16 +-
 include/linux/cmdline.h                      |  29 ++++
 include/linux/fb.h                           |   2 +-
 lib/Makefile                                 |   2 +-
 lib/cmdline_iter.c                           |  97 +++++++++++
 70 files changed, 1252 insertions(+), 708 deletions(-)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/cmdline_iter.c

-- 
2.39.2


^ permalink raw reply	[flat|nested] 232+ messages in thread

* [PATCH 00/99] fbdev: Fix memory leak in option parsing
@ 2023-03-06 15:58 ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Introduce struct option_iter and helpers to parse command-line
options with comma-separated key-value pairs. Then convert fbdev
drivers to the new interface. Fixes a memory leak in the parsing of
the video= option.

Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
caller; clarify ownership"), a call to fb_get_options() either
returned an internal string or a duplicated string; hence ownership of
the string's memory buffer was not well defined, but depended on how
users specified the video= option on the kernel command line. For
global settings, the caller owned the returned memory and for per-driver
settings, fb_get_options() owned the memory. As calling drivers were
unable to detect the case, the memory was leaked.

Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
clarify ownership") changed sematics to caller-owned strings. Drivers
still leaked the memory, but at least ownership was clear.

This patchset fixes the memory leak and changes string ownership back
to fb_get_options(). Patch 1 introduces struct option_iter and a few
helpers. The interface takes an option string, such as video=, in the
common form value1,key2:value2,value3 etc and returns the individial
comma-separated pairs. Various modules use this pattern, so the code
is located under lib/.

Patches 2 to 98 go through fbdev drivers and convert them to the new
interface. This often requires a number of cleanups. A driver would
typically refer to the option string's video mode. Such strings are now
copied to driver-allocated memory so that drivers don't refer directly
to the option string's memory. The option iterator then replaces manual
parsing loops based on strsep(",").

Patch 99 finally changes the ownership of the option string to be
internal to fb_get_option(); thereby fixing the memory leak. The option
iterator holds its own copy of the string and is not affected by the
change.

Most fbdev drivers only support to parse option strings if they are
built-in. I assume that's because of the original fuzzy semantics of
fb_get_options(). A later patchset could change the driver to respect
video= settings in any configuration.

Thomas Zimmermann (99):
  lib: Add option iterator
  fbdev/68328fb: Remove trailing whitespaces
  fbdev/68328fb: Remove unused option string
  fbdev/acornfb: Only init fb_info once
  fbdev/acornfb: Parse option string with struct option_iter
  fbdev/amifb: Duplicate video-mode option string
  fbdev/amifb: Parse option string with struct option_iter
  fbdev/arkfb: Duplicate video-mode option string
  fbdev/atafb: Duplicate video-mode option string
  fbdev/atafb: Parse option string with struct option_iter
  fbdev/aty: Duplicate video-mode option string
  fbdev/aty: Parse option string with struct option_iter
  fbdev/au1100fb: Parse option string with struct option_iter
  fbdev/au1200fb: Parse option string with struct option_iter
  fbdev/cirrusfb: Duplicate video-mode option string
  fbdev/cirrusfb: Parse option string with struct option_iter
  fbdev/controlfb: Remove trailing whitespaces
  fbdev/controlfb: Parse option string with struct option_iter
  fbdev/cyber2000fb: Parse option string with struct option_iter
  fbdev/efifb: Parse option string with struct option_iter
  fbdev/fm2fb: Parse option string with struct option_iter
  fbdev/fsl-diu-fb: Duplicate video-mode option string
  fbdev/fsl-diu-fb: Parse option string with struct option_iter
  fbdev/gbefb: Duplicate video-mode option string
  fbdev/gbefb: Parse option string with struct option_iter
  fbdev/geode: Duplicate video-mode option string
  fbdev/geode: Parse option string with struct option_iter
  fbdev/grvga: Duplicate video-mode option string
  fbdev/grvga: Parse option string with struct option_iter
  fbdev/gxt4500: Duplicate video-mode option string
  fbdev/hyperv_fb: Duplicate video-mode option string
  fbdev/i740fb: Duplicate video-mode option string
  fbdev/i740fb: Parse option string with struct option_iter
  fbdev/i810: Duplicate video-mode option string
  fbdev/i810: Parse option string with struct option_iter
  fbdev/imsttfb: Parse option string with struct option_iter
  fbdev/intelfb: Duplicate video-mode option string
  fbdev/intelfb: Parse option string with struct option_iter
  fbdev/imxfb: Duplicate video-mode option string
  fbdev/imxfb: Parse option string with struct option_iter
  fbdev/kyrofb: Duplicate video-mode option string
  fbdev/kyrofb: Parse option string with struct option_iter
  fbdev/macfb: Remove trailing whitespaces
  fbdev/macfb: Parse option string with struct option_iter
  fbdev/matroxfb: Parse option string with struct option_iter
  fbdev/mx3fb: Duplicate video-mode option string
  fbdev/mx3fb: Parse option string with struct option_iter
  fbdev/neofb: Duplicate video-mode option string
  fbdev/neofb: Parse option string with struct option_iter
  fbdev/nvidiafb: Duplicate video-mode option string
  fbdev/nvidiafb: Parse option string with struct option_iter
  fbdev/ocfb: Duplicate video-mode option string
  fbdev/ocfb: Parse option string with struct option_iter
  fbdev/omapfb: Parse option string with struct option_iter
  fbdev/platinumfb: Remove trailing whitespaces
  fbdev/platinumfb: Parse option string with struct option_iter
  fbdev/pm2fb: Duplicate video-mode option string
  fbdev/pm2fb: Parse option string with struct option_iter
  fbdev/pm3fb: Duplicate video-mode option string
  fbdev/pm3fb: Parse option string with struct option_iter
  fbdev/ps3fb: Duplicate video-mode option string
  fbdev/ps3fb: Parse option string with struct option_iter
  fbdev/pvr2fb: Duplicate video-mode option string
  fbdev/pvr2fb: Parse option string with struct option_iter
  fbdev/pxafb: Parse option string with struct option_iter
  fbdev/rivafb: Duplicate video-mode option string
  fbdev/rivafb: Parse option string with struct option_iter
  fbdev/s3fb: Duplicate video-mode option string
  fbdev/s3fb: Parse option string with struct option_iter
  fbdev/savagefb: Duplicate video-mode option string
  fbdev/savagefb: Parse option string with struct option_iter
  fbdev/sisfb: Constify mode string
  fbdev/sisfb: Parse option string with struct option_iter
  fbdev/skeletonfb: Parse option string with struct option_iter
  fbdev/sm712fb: Duplicate video-mode option string
  fbdev/sstfb: Duplicate video-mode option string
  fbdev/sstfb: Parse option string with struct option_iter
  fbdev/stifb: Remove trailing whitespaces
  fbdev/sti: Constify option string
  fbdev/tdfxfb: Duplicate video-mode option string
  fbdev/tdfxfb: Parse option string with struct option_iter
  fbdev/tgafb: Duplicate video-mode option string
  fbdev/tgafb: Parse option string with struct option_iter
  fbdev/tmiofb: Remove unused option string
  fbdev/tridentfb: Duplicate video-mode option string
  fbdev/tridentfb: Parse option string with struct option_iter
  fbdev/uvesafb: Duplicate video-mode option string
  fbdev/uvesafb: Parse option string with struct option_iter
  fbdev/valkyriefb: Remove trailing whitespaces
  fbdev/valkyriefb: Parse option string with struct option_iter
  fbdev/vermilion: Remove unused option string
  fbdev/vesafb: Parse option string with struct option_iter
  fbdev/vfb: Remove trailing whitespaces
  fbdev/vfb: Duplicate video-mode option string
  fbdev/vfb: Parse option string with struct option_iter
  fbdev/viafb: Parse option string with struct option_iter
  fbdev/vt8623fb: Duplicate video-mode option string
  staging/sm750fb: Parse option string with struct option_iter
  fbdev: Constify option strings

 Documentation/core-api/kernel-api.rst        |   9 ++
 drivers/staging/sm750fb/sm750.c              |  45 +++---
 drivers/video/fbdev/68328fb.c                |  24 +--
 drivers/video/fbdev/acornfb.c                |  25 ++-
 drivers/video/fbdev/amifb.c                  |  30 ++--
 drivers/video/fbdev/arkfb.c                  |  15 +-
 drivers/video/fbdev/atafb.c                  |  25 ++-
 drivers/video/fbdev/aty/aty128fb.c           |  28 +++-
 drivers/video/fbdev/aty/atyfb_base.c         |  29 +++-
 drivers/video/fbdev/aty/radeon_base.c        |  32 ++--
 drivers/video/fbdev/au1100fb.c               |  13 +-
 drivers/video/fbdev/au1200fb.c               |  15 +-
 drivers/video/fbdev/cirrusfb.c               |  37 +++--
 drivers/video/fbdev/controlfb.c              |  49 +++---
 drivers/video/fbdev/core/fb_cmdline.c        |  13 +-
 drivers/video/fbdev/core/modedb.c            |   8 +-
 drivers/video/fbdev/cyber2000fb.c            |  19 +--
 drivers/video/fbdev/efifb.c                  |  48 +++---
 drivers/video/fbdev/ep93xx-fb.c              |   2 +-
 drivers/video/fbdev/fm2fb.c                  |  16 +-
 drivers/video/fbdev/fsl-diu-fb.c             |  30 ++--
 drivers/video/fbdev/gbefb.c                  |  25 +--
 drivers/video/fbdev/geode/gx1fb_core.c       |  18 +--
 drivers/video/fbdev/geode/gxfb_core.c        |  25 +--
 drivers/video/fbdev/geode/lxfb_core.c        |  29 ++--
 drivers/video/fbdev/grvga.c                  |  32 +++-
 drivers/video/fbdev/gxt4500.c                |  18 ++-
 drivers/video/fbdev/hyperv_fb.c              |  18 ++-
 drivers/video/fbdev/i740fb.c                 |  32 ++--
 drivers/video/fbdev/i810/i810_main.c         |  30 +++-
 drivers/video/fbdev/imsttfb.c                |  18 ++-
 drivers/video/fbdev/imxfb.c                  |  23 ++-
 drivers/video/fbdev/intelfb/intelfbdrv.c     |  29 +++-
 drivers/video/fbdev/kyro/fbdev.c             |  27 ++--
 drivers/video/fbdev/macfb.c                  |  28 ++--
 drivers/video/fbdev/matrox/matroxfb_base.c   |  21 +--
 drivers/video/fbdev/mx3fb.c                  |  27 +++-
 drivers/video/fbdev/neofb.c                  |  32 ++--
 drivers/video/fbdev/nvidia/nvidia.c          |  32 ++--
 drivers/video/fbdev/ocfb.c                   |  25 ++-
 drivers/video/fbdev/omap/omapfb_main.c       |  15 +-
 drivers/video/fbdev/platinumfb.c             |  46 +++---
 drivers/video/fbdev/pm2fb.c                  |  31 ++--
 drivers/video/fbdev/pm3fb.c                  |  33 ++--
 drivers/video/fbdev/ps3fb.c                  |  32 ++--
 drivers/video/fbdev/pvr2fb.c                 |  29 ++--
 drivers/video/fbdev/pxafb.c                  |  20 ++-
 drivers/video/fbdev/riva/fbdev.c             |  32 ++--
 drivers/video/fbdev/s3fb.c                   |  33 ++--
 drivers/video/fbdev/savage/savagefb_driver.c |  26 ++-
 drivers/video/fbdev/sis/sis_main.c           |  26 +--
 drivers/video/fbdev/skeletonfb.c             |  17 +-
 drivers/video/fbdev/sm712fb.c                |  19 ++-
 drivers/video/fbdev/sstfb.c                  |  31 ++--
 drivers/video/fbdev/stifb.c                  | 162 +++++++++----------
 drivers/video/fbdev/tdfxfb.c                 |  27 ++--
 drivers/video/fbdev/tgafb.c                  |  35 ++--
 drivers/video/fbdev/tmiofb.c                 |  24 +--
 drivers/video/fbdev/tridentfb.c              |  33 ++--
 drivers/video/fbdev/uvesafb.c                |  27 ++--
 drivers/video/fbdev/valkyriefb.c             |  32 ++--
 drivers/video/fbdev/vermilion/vermilion.c    |   7 +-
 drivers/video/fbdev/vesafb.c                 |  18 ++-
 drivers/video/fbdev/vfb.c                    |  41 +++--
 drivers/video/fbdev/via/viafbdev.c           |  17 +-
 drivers/video/fbdev/vt8623fb.c               |  16 +-
 include/linux/cmdline.h                      |  29 ++++
 include/linux/fb.h                           |   2 +-
 lib/Makefile                                 |   2 +-
 lib/cmdline_iter.c                           |  97 +++++++++++
 70 files changed, 1252 insertions(+), 708 deletions(-)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/cmdline_iter.c

-- 
2.39.2


^ permalink raw reply	[flat|nested] 232+ messages in thread

* [PATCH 01/99] lib: Add option iterator
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Add struct option_iter and helpers that walk over individual options
of an option string. Add documentation.

Kernel parameters often have the format of

  param=opt1,opt2:val,opt3

where the option string contains a number of comma-separated options.
Drivers usually use strsep() in a loop to extract individual options
from the string. Each call to strsep() modifies the given string, so
callers have to duplicate kernel parameters that are to be parsed
multiple times.

The new struct option_iter and its helpers wrap this code behind a
clean interface. Drivers can iterate over the options without having
to know the details of the option-string format. The iterator handles
string memory internally without modifying the original options.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 Documentation/core-api/kernel-api.rst |  9 +++
 include/linux/cmdline.h               | 29 ++++++++
 lib/Makefile                          |  2 +-
 lib/cmdline_iter.c                    | 97 +++++++++++++++++++++++++++
 4 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/cmdline_iter.c

diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst
index 62f961610773..cdc7ba8decf9 100644
--- a/Documentation/core-api/kernel-api.rst
+++ b/Documentation/core-api/kernel-api.rst
@@ -93,9 +93,18 @@ Bitmap Operations
 Command-line Parsing
 --------------------
 
+.. kernel-doc:: lib/cmdline_iter.c
+   :doc: overview
+
 .. kernel-doc:: lib/cmdline.c
    :export:
 
+.. kernel-doc:: lib/cmdline_iter.c
+   :export:
+
+.. kernel-doc:: include/linux/cmdline.h
+   :internal:
+
 Sorting
 -------
 
diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index 000000000000..5d7e648e98a5
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef LINUX_CMDLINE_H
+#define LINUX_CMDLINE_H
+
+/**
+ * struct option_iter - Iterates over string of kernel or module options
+ */
+struct option_iter {
+	char *optbuf;
+	char *next_opt;
+};
+
+void option_iter_init(struct option_iter *iter, const char *options);
+void option_iter_release(struct option_iter *iter);
+const char *option_iter_incr(struct option_iter *iter);
+
+/**
+ * option_iter_next - Loop condition to move over options
+ * @iter_:	the iterator
+ * @opt_:	the name of the option variable
+ *
+ * Iterates over option strings as part of a while loop and
+ * stores the current option in opt_.
+ */
+#define option_iter_next(iter_, opt_) \
+	(((opt_) = option_iter_incr(iter_)) != NULL)
+
+#endif
diff --git a/lib/Makefile b/lib/Makefile
index 4d9461bfea42..829ea6647d7a 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -27,7 +27,7 @@ KASAN_SANITIZE_string.o := n
 CFLAGS_string.o += -fno-stack-protector
 endif
 
-lib-y := ctype.o string.o vsprintf.o cmdline.o \
+lib-y := ctype.o string.o vsprintf.o cmdline.o cmdline_iter.o \
 	 rbtree.o radix-tree.o timerqueue.o xarray.o \
 	 maple_tree.o idr.o extable.o irq_regs.o argv_split.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
diff --git a/lib/cmdline_iter.c b/lib/cmdline_iter.c
new file mode 100644
index 000000000000..d9371dfea08b
--- /dev/null
+++ b/lib/cmdline_iter.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/cmdline.h>
+#include <linux/export.h>
+#include <linux/slab.h>
+
+/**
+ * DOC: overview
+ *
+ * A kernel parameter's option string can contain multiple comma-separated
+ * options. Modules can parse an option string with struct &option_iter and
+ * its helpers. After obtaining the string, initialize and instance of the
+ * option iterator and loop iver its content as show below.
+ *
+ * .. code-block:: c
+ *
+ *	const char *options = ...; // provided option string
+ *
+ *	struct option_iter iter;
+ *	const char *opt;
+ *
+ *	option_iter_init(&iter, options);
+ *
+ *	while (option_iter_next(&iter, &opt)) {
+ *		if (!strcmp(opt, "foo"))
+ *			...
+ *		else (strcmp(opt, "bar"))
+ *			...
+ *		else
+ *			pr_warn("unknown option %s\n", opt);
+ *	}
+ *
+ *	option_iter_release(&iter);
+ *
+ * The call to option_iter_init() initializes the iterator instance
+ * from the option string. The while loop walks over the individual
+ * options in the sting and returns each in the second argument. The
+ * returned memory is owned by the iterator instance and callers may
+ * not modify or free it. The call to option_iter_release() frees all
+ * resources of the iterator. This process does not modify the original
+ * option string. If the option string contains an empty option (i.e.,
+ * two commas next to each other), option_iter_next() skips the empty
+ * option automatically.
+ */
+
+/**
+ * option_iter_init - Initializes an option iterator
+ * @iter:	the iterator to initialize
+ * @options:	the options string
+ */
+void option_iter_init(struct option_iter *iter, const char *options)
+{
+	if (options && *options)
+		iter->optbuf = kstrdup(options, GFP_KERNEL); // can be NULL
+	else
+		iter->optbuf = NULL;
+	iter->next_opt = iter->optbuf;
+}
+EXPORT_SYMBOL(option_iter_init);
+
+/**
+ * option_iter_release - Releases an option iterator's resources
+ * @iter:	the iterator
+ */
+void option_iter_release(struct option_iter *iter)
+{
+	kfree(iter->optbuf);
+	iter->next_opt = NULL;
+}
+EXPORT_SYMBOL(option_iter_release);
+
+/**
+ * option_iter_incr - Return current option and advance to the next
+ * @iter:	the iterator
+ *
+ * Returns:
+ * The current option string, or NULL if there are no more options.
+ */
+const char *option_iter_incr(struct option_iter *iter)
+{
+	char *opt;
+
+	if (!iter->next_opt) { // can be OK if kstrdup failed
+		if (iter->optbuf) // iter has already been released; logic error
+			pr_err("Incrementing option iterator without string\n");
+		return NULL;
+	}
+
+	do {
+		opt = strsep(&iter->next_opt, ",");
+		if (!opt)
+			return NULL;
+	} while (!*opt); // found empty option string, try next
+
+	return opt;
+}
+EXPORT_SYMBOL(option_iter_incr);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 01/99] lib: Add option iterator
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Add struct option_iter and helpers that walk over individual options
of an option string. Add documentation.

Kernel parameters often have the format of

  param=opt1,opt2:val,opt3

where the option string contains a number of comma-separated options.
Drivers usually use strsep() in a loop to extract individual options
from the string. Each call to strsep() modifies the given string, so
callers have to duplicate kernel parameters that are to be parsed
multiple times.

The new struct option_iter and its helpers wrap this code behind a
clean interface. Drivers can iterate over the options without having
to know the details of the option-string format. The iterator handles
string memory internally without modifying the original options.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 Documentation/core-api/kernel-api.rst |  9 +++
 include/linux/cmdline.h               | 29 ++++++++
 lib/Makefile                          |  2 +-
 lib/cmdline_iter.c                    | 97 +++++++++++++++++++++++++++
 4 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/cmdline_iter.c

diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst
index 62f961610773..cdc7ba8decf9 100644
--- a/Documentation/core-api/kernel-api.rst
+++ b/Documentation/core-api/kernel-api.rst
@@ -93,9 +93,18 @@ Bitmap Operations
 Command-line Parsing
 --------------------
 
+.. kernel-doc:: lib/cmdline_iter.c
+   :doc: overview
+
 .. kernel-doc:: lib/cmdline.c
    :export:
 
+.. kernel-doc:: lib/cmdline_iter.c
+   :export:
+
+.. kernel-doc:: include/linux/cmdline.h
+   :internal:
+
 Sorting
 -------
 
diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index 000000000000..5d7e648e98a5
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef LINUX_CMDLINE_H
+#define LINUX_CMDLINE_H
+
+/**
+ * struct option_iter - Iterates over string of kernel or module options
+ */
+struct option_iter {
+	char *optbuf;
+	char *next_opt;
+};
+
+void option_iter_init(struct option_iter *iter, const char *options);
+void option_iter_release(struct option_iter *iter);
+const char *option_iter_incr(struct option_iter *iter);
+
+/**
+ * option_iter_next - Loop condition to move over options
+ * @iter_:	the iterator
+ * @opt_:	the name of the option variable
+ *
+ * Iterates over option strings as part of a while loop and
+ * stores the current option in opt_.
+ */
+#define option_iter_next(iter_, opt_) \
+	(((opt_) = option_iter_incr(iter_)) != NULL)
+
+#endif
diff --git a/lib/Makefile b/lib/Makefile
index 4d9461bfea42..829ea6647d7a 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -27,7 +27,7 @@ KASAN_SANITIZE_string.o := n
 CFLAGS_string.o += -fno-stack-protector
 endif
 
-lib-y := ctype.o string.o vsprintf.o cmdline.o \
+lib-y := ctype.o string.o vsprintf.o cmdline.o cmdline_iter.o \
 	 rbtree.o radix-tree.o timerqueue.o xarray.o \
 	 maple_tree.o idr.o extable.o irq_regs.o argv_split.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
diff --git a/lib/cmdline_iter.c b/lib/cmdline_iter.c
new file mode 100644
index 000000000000..d9371dfea08b
--- /dev/null
+++ b/lib/cmdline_iter.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/cmdline.h>
+#include <linux/export.h>
+#include <linux/slab.h>
+
+/**
+ * DOC: overview
+ *
+ * A kernel parameter's option string can contain multiple comma-separated
+ * options. Modules can parse an option string with struct &option_iter and
+ * its helpers. After obtaining the string, initialize and instance of the
+ * option iterator and loop iver its content as show below.
+ *
+ * .. code-block:: c
+ *
+ *	const char *options = ...; // provided option string
+ *
+ *	struct option_iter iter;
+ *	const char *opt;
+ *
+ *	option_iter_init(&iter, options);
+ *
+ *	while (option_iter_next(&iter, &opt)) {
+ *		if (!strcmp(opt, "foo"))
+ *			...
+ *		else (strcmp(opt, "bar"))
+ *			...
+ *		else
+ *			pr_warn("unknown option %s\n", opt);
+ *	}
+ *
+ *	option_iter_release(&iter);
+ *
+ * The call to option_iter_init() initializes the iterator instance
+ * from the option string. The while loop walks over the individual
+ * options in the sting and returns each in the second argument. The
+ * returned memory is owned by the iterator instance and callers may
+ * not modify or free it. The call to option_iter_release() frees all
+ * resources of the iterator. This process does not modify the original
+ * option string. If the option string contains an empty option (i.e.,
+ * two commas next to each other), option_iter_next() skips the empty
+ * option automatically.
+ */
+
+/**
+ * option_iter_init - Initializes an option iterator
+ * @iter:	the iterator to initialize
+ * @options:	the options string
+ */
+void option_iter_init(struct option_iter *iter, const char *options)
+{
+	if (options && *options)
+		iter->optbuf = kstrdup(options, GFP_KERNEL); // can be NULL
+	else
+		iter->optbuf = NULL;
+	iter->next_opt = iter->optbuf;
+}
+EXPORT_SYMBOL(option_iter_init);
+
+/**
+ * option_iter_release - Releases an option iterator's resources
+ * @iter:	the iterator
+ */
+void option_iter_release(struct option_iter *iter)
+{
+	kfree(iter->optbuf);
+	iter->next_opt = NULL;
+}
+EXPORT_SYMBOL(option_iter_release);
+
+/**
+ * option_iter_incr - Return current option and advance to the next
+ * @iter:	the iterator
+ *
+ * Returns:
+ * The current option string, or NULL if there are no more options.
+ */
+const char *option_iter_incr(struct option_iter *iter)
+{
+	char *opt;
+
+	if (!iter->next_opt) { // can be OK if kstrdup failed
+		if (iter->optbuf) // iter has already been released; logic error
+			pr_err("Incrementing option iterator without string\n");
+		return NULL;
+	}
+
+	do {
+		opt = strsep(&iter->next_opt, ",");
+		if (!opt)
+			return NULL;
+	} while (!*opt); // found empty option string, try next
+
+	return opt;
+}
+EXPORT_SYMBOL(option_iter_incr);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 02/99] fbdev/68328fb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/68328fb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/68328fb.c b/drivers/video/fbdev/68328fb.c
index 7db03ed77c76..7fe56ecbe4e6 100644
--- a/drivers/video/fbdev/68328fb.c
+++ b/drivers/video/fbdev/68328fb.c
@@ -123,7 +123,7 @@ static u_long get_line_length(int xres_virtual, int bpp)
      *  First part, xxxfb_check_var, must not write anything
      *  to hardware, it should only verify and adjust var.
      *  This means it doesn't alter par but it does use hardware
-     *  data from it to check this var. 
+     *  data from it to check this var.
      */
 
 static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
@@ -181,7 +181,7 @@ static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
 
 	/*
 	 * Now that we checked it we alter var. The reason being is that the video
-	 * mode passed in might not work but slight changes to it might make it 
+	 * mode passed in might not work but slight changes to it might make it
 	 * work. This way we let the user know what is acceptable.
 	 */
 	switch (var->bits_per_pixel) {
@@ -256,8 +256,8 @@ static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
 }
 
 /* This routine actually sets the video mode. It's in here where we
- * the hardware state info->par and fix which can be affected by the 
- * change in par. For this driver it doesn't do much. 
+ * the hardware state info->par and fix which can be affected by the
+ * change in par. For this driver it doesn't do much.
  */
 static int mc68x328fb_set_par(struct fb_info *info)
 {
@@ -294,7 +294,7 @@ static int mc68x328fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 	 *   {hardwarespecific} contains width of RAMDAC
 	 *   cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
 	 *   RAMDAC[X] is programmed to (red, green, blue)
-	 * 
+	 *
 	 * Pseudocolor:
 	 *    uses offset = 0 && length = RAMDAC register width.
 	 *    var->{color}.offset is 0
@@ -383,7 +383,7 @@ static int mc68x328fb_pan_display(struct fb_var_screeninfo *var,
 }
 
     /*
-     *  Most drivers don't need their own mmap function 
+     *  Most drivers don't need their own mmap function
      */
 
 static int mc68x328fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 02/99] fbdev/68328fb: Remove trailing whitespaces
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/68328fb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/68328fb.c b/drivers/video/fbdev/68328fb.c
index 7db03ed77c76..7fe56ecbe4e6 100644
--- a/drivers/video/fbdev/68328fb.c
+++ b/drivers/video/fbdev/68328fb.c
@@ -123,7 +123,7 @@ static u_long get_line_length(int xres_virtual, int bpp)
      *  First part, xxxfb_check_var, must not write anything
      *  to hardware, it should only verify and adjust var.
      *  This means it doesn't alter par but it does use hardware
-     *  data from it to check this var. 
+     *  data from it to check this var.
      */
 
 static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
@@ -181,7 +181,7 @@ static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
 
 	/*
 	 * Now that we checked it we alter var. The reason being is that the video
-	 * mode passed in might not work but slight changes to it might make it 
+	 * mode passed in might not work but slight changes to it might make it
 	 * work. This way we let the user know what is acceptable.
 	 */
 	switch (var->bits_per_pixel) {
@@ -256,8 +256,8 @@ static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
 }
 
 /* This routine actually sets the video mode. It's in here where we
- * the hardware state info->par and fix which can be affected by the 
- * change in par. For this driver it doesn't do much. 
+ * the hardware state info->par and fix which can be affected by the
+ * change in par. For this driver it doesn't do much.
  */
 static int mc68x328fb_set_par(struct fb_info *info)
 {
@@ -294,7 +294,7 @@ static int mc68x328fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 	 *   {hardwarespecific} contains width of RAMDAC
 	 *   cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
 	 *   RAMDAC[X] is programmed to (red, green, blue)
-	 * 
+	 *
 	 * Pseudocolor:
 	 *    uses offset = 0 && length = RAMDAC register width.
 	 *    var->{color}.offset is 0
@@ -383,7 +383,7 @@ static int mc68x328fb_pan_display(struct fb_var_screeninfo *var,
 }
 
     /*
-     *  Most drivers don't need their own mmap function 
+     *  Most drivers don't need their own mmap function
      */
 
 static int mc68x328fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 03/99] fbdev/68328fb: Remove unused option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

The option string is unused. Remove the variable and a related
helper function. No functional change.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/68328fb.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/video/fbdev/68328fb.c b/drivers/video/fbdev/68328fb.c
index 7fe56ecbe4e6..f2d70df4104b 100644
--- a/drivers/video/fbdev/68328fb.c
+++ b/drivers/video/fbdev/68328fb.c
@@ -400,13 +400,6 @@ static int mc68x328fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 #endif
 }
 
-static int __init mc68x328fb_setup(char *options)
-{
-	if (!options || !*options)
-		return 1;
-	return 1;
-}
-
     /*
      *  Initialisation
      */
@@ -414,11 +407,8 @@ static int __init mc68x328fb_setup(char *options)
 static int __init mc68x328fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
-
-	if (fb_get_options("68328fb", &option))
+	if (fb_get_options("68328fb", NULL))
 		return -ENODEV;
-	mc68x328fb_setup(option);
 #endif
 	/*
 	 *  initialize the default mode from the LCD controller registers
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 03/99] fbdev/68328fb: Remove unused option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

The option string is unused. Remove the variable and a related
helper function. No functional change.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/68328fb.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/video/fbdev/68328fb.c b/drivers/video/fbdev/68328fb.c
index 7fe56ecbe4e6..f2d70df4104b 100644
--- a/drivers/video/fbdev/68328fb.c
+++ b/drivers/video/fbdev/68328fb.c
@@ -400,13 +400,6 @@ static int mc68x328fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 #endif
 }
 
-static int __init mc68x328fb_setup(char *options)
-{
-	if (!options || !*options)
-		return 1;
-	return 1;
-}
-
     /*
      *  Initialisation
      */
@@ -414,11 +407,8 @@ static int __init mc68x328fb_setup(char *options)
 static int __init mc68x328fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
-
-	if (fb_get_options("68328fb", &option))
+	if (fb_get_options("68328fb", NULL))
 		return -ENODEV;
-	mc68x328fb_setup(option);
 #endif
 	/*
 	 *  initialize the default mode from the LCD controller registers
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 04/99] fbdev/acornfb: Only init fb_info once
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Init the fb_info instance once before parsing options. The current
code initializes the instance once again after parsing options, which
clears any resolution settings that have been given in the options
string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/acornfb.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 1b72edc01cfb..8642136a6bdc 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -887,8 +887,6 @@ static int acornfb_setup(char *options)
 	if (!options || !*options)
 		return 0;
 
-	acornfb_init_fbinfo();
-
 	while ((opt = strsep(&options, ",")) != NULL) {
 		if (!*opt)
 			continue;
@@ -930,9 +928,8 @@ static int acornfb_probe(struct platform_device *dev)
 
 	if (fb_get_options("acornfb", &option))
 		return -ENODEV;
-	acornfb_setup(option);
-
 	acornfb_init_fbinfo();
+	acornfb_setup(option);
 
 	current_par.dev = &dev->dev;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 04/99] fbdev/acornfb: Only init fb_info once
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Init the fb_info instance once before parsing options. The current
code initializes the instance once again after parsing options, which
clears any resolution settings that have been given in the options
string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/acornfb.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 1b72edc01cfb..8642136a6bdc 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -887,8 +887,6 @@ static int acornfb_setup(char *options)
 	if (!options || !*options)
 		return 0;
 
-	acornfb_init_fbinfo();
-
 	while ((opt = strsep(&options, ",")) != NULL) {
 		if (!*opt)
 			continue;
@@ -930,9 +928,8 @@ static int acornfb_probe(struct platform_device *dev)
 
 	if (fb_get_options("acornfb", &option))
 		return -ENODEV;
-	acornfb_setup(option);
-
 	acornfb_init_fbinfo();
+	acornfb_setup(option);
 
 	current_par.dev = &dev->dev;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 05/99] fbdev/acornfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/acornfb.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 8642136a6bdc..1d6dec45615c 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -14,6 +14,7 @@
  *  - Blanking 8bpp displays with VIDC
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -879,17 +880,15 @@ static struct options {
 	{ NULL, NULL }
 };
 
-static int acornfb_setup(char *options)
+static int acornfb_setup(const char *options)
 {
-	struct options *optp;
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	while (option_iter_next(&iter, opt)) {
+		struct options *optp;
 
 		for (optp = opt_table; optp->name; optp++) {
 			int optlen;
@@ -907,6 +906,9 @@ static int acornfb_setup(char *options)
 			printk(KERN_ERR "acornfb: unknown parameter: %s\n",
 			       opt);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 05/99] fbdev/acornfb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/acornfb.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 8642136a6bdc..1d6dec45615c 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -14,6 +14,7 @@
  *  - Blanking 8bpp displays with VIDC
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -879,17 +880,15 @@ static struct options {
 	{ NULL, NULL }
 };
 
-static int acornfb_setup(char *options)
+static int acornfb_setup(const char *options)
 {
-	struct options *optp;
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	while (option_iter_next(&iter, opt)) {
+		struct options *optp;
 
 		for (optp = opt_table; optp->name; optp++) {
 			int optlen;
@@ -907,6 +906,9 @@ static int acornfb_setup(char *options)
 			printk(KERN_ERR "acornfb: unknown parameter: %s\n",
 			       opt);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 06/99] fbdev/amifb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
free the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/amifb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index d88265dbebf4..6edfd0bfdd57 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -2363,8 +2363,17 @@ static int __init amifb_setup(char *options)
 			amifb_setup_mcap(this_opt + 11);
 		else if (!strncmp(this_opt, "fstart:", 7))
 			min_fstrt = simple_strtoul(this_opt + 7, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "amifb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "amifb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	if (min_fstrt < 48)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 06/99] fbdev/amifb: Duplicate video-mode option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
free the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/amifb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index d88265dbebf4..6edfd0bfdd57 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -2363,8 +2363,17 @@ static int __init amifb_setup(char *options)
 			amifb_setup_mcap(this_opt + 11);
 		else if (!strncmp(this_opt, "fstart:", 7))
 			min_fstrt = simple_strtoul(this_opt + 7, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "amifb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "amifb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	if (min_fstrt < 48)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/amifb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index 6edfd0bfdd57..b968cf2c5f06 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -40,6 +40,7 @@
  * for more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2345,16 +2346,14 @@ static void __init amifb_setup_mcap(char *spec)
 	amifb_vfmax = vmax;
 }
 
-static int __init amifb_setup(char *options)
+static int __init amifb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "inverse")) {
 			fb_invert_cmaps();
 		} else if (!strcmp(this_opt, "ilbm"))
@@ -2376,6 +2375,8 @@ static int __init amifb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	if (min_fstrt < 48)
 		min_fstrt = 48;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/amifb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index 6edfd0bfdd57..b968cf2c5f06 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -40,6 +40,7 @@
  * for more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2345,16 +2346,14 @@ static void __init amifb_setup_mcap(char *spec)
 	amifb_vfmax = vmax;
 }
 
-static int __init amifb_setup(char *options)
+static int __init amifb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "inverse")) {
 			fb_invert_cmaps();
 		} else if (!strcmp(this_opt, "ilbm"))
@@ -2376,6 +2375,8 @@ static int __init amifb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	if (min_fstrt < 48)
 		min_fstrt = 48;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/arkfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index 60a96fdb5dd8..f83fcdaec7a0 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -1196,8 +1196,17 @@ static int __init arkfb_init(void)
 	if (fb_get_options("arkfb", &option))
 		return -ENODEV;
 
-	if (option && *option)
-		mode_option = option;
+	if (option && *option) {
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
+		if (WARN(ret < 0, "arkfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "arkfb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
+	}
 #endif
 
 	pr_debug("arkfb: initializing\n");
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/arkfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index 60a96fdb5dd8..f83fcdaec7a0 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -1196,8 +1196,17 @@ static int __init arkfb_init(void)
 	if (fb_get_options("arkfb", &option))
 		return -ENODEV;
 
-	if (option && *option)
-		mode_option = option;
+	if (option && *option) {
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
+		if (WARN(ret < 0, "arkfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "arkfb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
+	}
 #endif
 
 	pr_debug("arkfb: initializing\n");
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 09/99] fbdev/atafb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/atafb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 2bc4089865e6..331e72096ebb 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -2946,8 +2946,16 @@ static int __init atafb_setup(char *options)
 		if (!*this_opt)
 			continue;
 		if ((temp = get_video_mode(this_opt))) {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "atafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "atafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 			default_par = temp;
-			mode_option = this_opt;
 		} else if (!strcmp(this_opt, "inverse"))
 			fb_invert_cmaps();
 		else if (!strncmp(this_opt, "hwscroll_", 9)) {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 09/99] fbdev/atafb: Duplicate video-mode option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/atafb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 2bc4089865e6..331e72096ebb 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -2946,8 +2946,16 @@ static int __init atafb_setup(char *options)
 		if (!*this_opt)
 			continue;
 		if ((temp = get_video_mode(this_opt))) {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "atafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "atafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 			default_par = temp;
-			mode_option = this_opt;
 		} else if (!strcmp(this_opt, "inverse"))
 			fb_invert_cmaps();
 		else if (!strncmp(this_opt, "hwscroll_", 9)) {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/atafb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 331e72096ebb..82d5567f2ffb 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -47,6 +47,7 @@
 #define ATAFB_EXT
 #define ATAFB_FALCON
 
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
@@ -2934,17 +2935,16 @@ static void __init atafb_setup_user(char *spec)
 	}
 }
 
-static int __init atafb_setup(char *options)
+static int __init atafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 	int temp;
 
 	if (!options || !*options)
 		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if ((temp = get_video_mode(this_opt))) {
 			static char mode_option_buf[256];
 			int ret;
@@ -2988,6 +2988,9 @@ static int __init atafb_setup(char *options)
 		else if (!strncmp(this_opt, "R", 1))
 			atafb_setup_user(this_opt + 1);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/atafb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 331e72096ebb..82d5567f2ffb 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -47,6 +47,7 @@
 #define ATAFB_EXT
 #define ATAFB_FALCON
 
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
@@ -2934,17 +2935,16 @@ static void __init atafb_setup_user(char *spec)
 	}
 }
 
-static int __init atafb_setup(char *options)
+static int __init atafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 	int temp;
 
 	if (!options || !*options)
 		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if ((temp = get_video_mode(this_opt))) {
 			static char mode_option_buf[256];
 			int ret;
@@ -2988,6 +2988,9 @@ static int __init atafb_setup(char *options)
 		else if (!strncmp(this_opt, "R", 1))
 			atafb_setup_user(this_opt + 1);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 11/99] fbdev/aty: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/aty/aty128fb.c    | 12 +++++++++++-
 drivers/video/fbdev/aty/atyfb_base.c  | 13 +++++++++++--
 drivers/video/fbdev/aty/radeon_base.c | 13 +++++++++++--
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
index 36a9ac05a340..3c08904a107f 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -1723,7 +1723,17 @@ static int aty128fb_setup(char *options)
 			continue;
 		}
 #endif /* CONFIG_PPC_PMAC */
-		mode_option = this_opt;
+		{
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "aty128: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "aty128fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
index b02e4e645035..5e6e83472c30 100644
--- a/drivers/video/fbdev/aty/atyfb_base.c
+++ b/drivers/video/fbdev/aty/atyfb_base.c
@@ -3896,8 +3896,17 @@ static int __init atyfb_setup(char *options)
 			}
 		}
 #endif
-		else
-			mode = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "atyfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "atyfb: option too long\n"))
+				continue;
+			mode = mode_option_buf;
+		}
 	}
 	return 0;
 }
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index 657064227de8..b885a7cc2424 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -2596,8 +2596,17 @@ static int __init radeonfb_setup (char *options)
 		} else if (!strncmp(this_opt, "ignore_devlist", 14)) {
 			ignore_devlist = 1;
 #endif
-		} else
-			mode_option = this_opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "radeonfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "radeonfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 11/99] fbdev/aty: Duplicate video-mode option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/aty/aty128fb.c    | 12 +++++++++++-
 drivers/video/fbdev/aty/atyfb_base.c  | 13 +++++++++++--
 drivers/video/fbdev/aty/radeon_base.c | 13 +++++++++++--
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
index 36a9ac05a340..3c08904a107f 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -1723,7 +1723,17 @@ static int aty128fb_setup(char *options)
 			continue;
 		}
 #endif /* CONFIG_PPC_PMAC */
-		mode_option = this_opt;
+		{
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "aty128: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "aty128fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
index b02e4e645035..5e6e83472c30 100644
--- a/drivers/video/fbdev/aty/atyfb_base.c
+++ b/drivers/video/fbdev/aty/atyfb_base.c
@@ -3896,8 +3896,17 @@ static int __init atyfb_setup(char *options)
 			}
 		}
 #endif
-		else
-			mode = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "atyfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "atyfb: option too long\n"))
+				continue;
+			mode = mode_option_buf;
+		}
 	}
 	return 0;
 }
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index 657064227de8..b885a7cc2424 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -2596,8 +2596,17 @@ static int __init radeonfb_setup (char *options)
 		} else if (!strncmp(this_opt, "ignore_devlist", 14)) {
 			ignore_devlist = 1;
 #endif
-		} else
-			mode_option = this_opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "radeonfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "radeonfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 12/99] fbdev/aty: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/aty/aty128fb.c    | 14 +++++++++-----
 drivers/video/fbdev/aty/atyfb_base.c  | 14 +++++++++-----
 drivers/video/fbdev/aty/radeon_base.c | 17 +++++++++--------
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
index 3c08904a107f..4a200eabe80b 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -48,6 +48,7 @@
 
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -1673,14 +1674,14 @@ static int aty128fb_sync(struct fb_info *info)
 }
 
 #ifndef MODULE
-static int aty128fb_setup(char *options)
+static int aty128fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "lcd:", 4)) {
 			default_lcd_on = simple_strtoul(this_opt+4, NULL, 0);
 			continue;
@@ -1735,6 +1736,9 @@ static int aty128fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
index 5e6e83472c30..1920ee5c9a2a 100644
--- a/drivers/video/fbdev/aty/atyfb_base.c
+++ b/drivers/video/fbdev/aty/atyfb_base.c
@@ -49,6 +49,7 @@
 ******************************************************************************/
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/compat.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
@@ -3831,14 +3832,14 @@ static struct pci_driver atyfb_driver = {
 #endif /* CONFIG_PCI */
 
 #ifndef MODULE
-static int __init atyfb_setup(char *options)
+static int __init atyfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = true;
 		} else if (!strncmp(this_opt, "nomtrr", 6)) {
@@ -3908,6 +3909,9 @@ static int __init atyfb_setup(char *options)
 			mode = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index b885a7cc2424..185cd98ad59d 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -55,6 +55,7 @@
 #include "radeonfb.h"
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -2561,17 +2562,14 @@ static struct pci_driver radeonfb_driver = {
 };
 
 #ifndef MODULE
-static int __init radeonfb_setup (char *options)
+static int __init radeonfb_setup (const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep (&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = 1;
 		} else if (!strncmp(this_opt, "mirror", 6)) {
@@ -2608,6 +2606,9 @@ static int __init radeonfb_setup (char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 12/99] fbdev/aty: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/aty/aty128fb.c    | 14 +++++++++-----
 drivers/video/fbdev/aty/atyfb_base.c  | 14 +++++++++-----
 drivers/video/fbdev/aty/radeon_base.c | 17 +++++++++--------
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
index 3c08904a107f..4a200eabe80b 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -48,6 +48,7 @@
 
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -1673,14 +1674,14 @@ static int aty128fb_sync(struct fb_info *info)
 }
 
 #ifndef MODULE
-static int aty128fb_setup(char *options)
+static int aty128fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "lcd:", 4)) {
 			default_lcd_on = simple_strtoul(this_opt+4, NULL, 0);
 			continue;
@@ -1735,6 +1736,9 @@ static int aty128fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
index 5e6e83472c30..1920ee5c9a2a 100644
--- a/drivers/video/fbdev/aty/atyfb_base.c
+++ b/drivers/video/fbdev/aty/atyfb_base.c
@@ -49,6 +49,7 @@
 ******************************************************************************/
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/compat.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
@@ -3831,14 +3832,14 @@ static struct pci_driver atyfb_driver = {
 #endif /* CONFIG_PCI */
 
 #ifndef MODULE
-static int __init atyfb_setup(char *options)
+static int __init atyfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = true;
 		} else if (!strncmp(this_opt, "nomtrr", 6)) {
@@ -3908,6 +3909,9 @@ static int __init atyfb_setup(char *options)
 			mode = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index b885a7cc2424..185cd98ad59d 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -55,6 +55,7 @@
 #include "radeonfb.h"
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -2561,17 +2562,14 @@ static struct pci_driver radeonfb_driver = {
 };
 
 #ifndef MODULE
-static int __init radeonfb_setup (char *options)
+static int __init radeonfb_setup (const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep (&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = 1;
 		} else if (!strncmp(this_opt, "mirror", 6)) {
@@ -2608,6 +2606,9 @@ static int __init radeonfb_setup (char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 13/99] fbdev/au1100fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/au1100fb.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c
index 519313b8bb00..17dae92ac53f 100644
--- a/drivers/video/fbdev/au1100fb.c
+++ b/drivers/video/fbdev/au1100fb.c
@@ -42,6 +42,7 @@
  *  675 Mass Ave, Cambridge, MA 02139, USA.
  */
 #include <linux/clk.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -365,7 +366,9 @@ static const struct fb_ops au1100fb_ops =
 
 static int au1100fb_setup(struct au1100fb_device *fbdev)
 {
-	char *this_opt, *options;
+	char *options;
+	struct option_iter iter;
+	const char *this_opt;
 	int num_panels = ARRAY_SIZE(known_lcd_panels);
 
 	if (num_panels <= 0) {
@@ -375,10 +378,10 @@ static int au1100fb_setup(struct au1100fb_device *fbdev)
 
 	if (fb_get_options(DRIVER_NAME, &options))
 		return -ENODEV;
-	if (!options)
-		return -ENODEV;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		/* Panel option */
 		if (!strncmp(this_opt, "panel:", 6)) {
 			int i;
@@ -401,6 +404,8 @@ static int au1100fb_setup(struct au1100fb_device *fbdev)
 			print_warn("Unsupported option \"%s\"", this_opt);
 	}
 
+	option_iter_release(&iter);
+
 	print_info("Panel=%s", fbdev->panel->name);
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 13/99] fbdev/au1100fb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/au1100fb.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c
index 519313b8bb00..17dae92ac53f 100644
--- a/drivers/video/fbdev/au1100fb.c
+++ b/drivers/video/fbdev/au1100fb.c
@@ -42,6 +42,7 @@
  *  675 Mass Ave, Cambridge, MA 02139, USA.
  */
 #include <linux/clk.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -365,7 +366,9 @@ static const struct fb_ops au1100fb_ops =
 
 static int au1100fb_setup(struct au1100fb_device *fbdev)
 {
-	char *this_opt, *options;
+	char *options;
+	struct option_iter iter;
+	const char *this_opt;
 	int num_panels = ARRAY_SIZE(known_lcd_panels);
 
 	if (num_panels <= 0) {
@@ -375,10 +378,10 @@ static int au1100fb_setup(struct au1100fb_device *fbdev)
 
 	if (fb_get_options(DRIVER_NAME, &options))
 		return -ENODEV;
-	if (!options)
-		return -ENODEV;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		/* Panel option */
 		if (!strncmp(this_opt, "panel:", 6)) {
 			int i;
@@ -401,6 +404,8 @@ static int au1100fb_setup(struct au1100fb_device *fbdev)
 			print_warn("Unsupported option \"%s\"", this_opt);
 	}
 
+	option_iter_release(&iter);
+
 	print_info("Panel=%s", fbdev->panel->name);
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 14/99] fbdev/au1200fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/au1200fb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c
index 81c315454428..31a3f6afd8aa 100644
--- a/drivers/video/fbdev/au1200fb.c
+++ b/drivers/video/fbdev/au1200fb.c
@@ -31,6 +31,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/kernel.h>
@@ -1578,16 +1579,17 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
 static int au1200fb_setup(struct au1200fb_platdata *pd)
 {
 	char *options = NULL;
-	char *this_opt, *endptr;
+	struct option_iter iter;
+	const char *this_opt;
+	char *endptr;
 	int num_panels = ARRAY_SIZE(known_lcd_panels);
 	int panel_idx = -1;
 
 	fb_get_options(DRIVER_NAME, &options);
 
-	if (!options)
-		goto out;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		/* Panel option - can be panel name,
 		 * "bs" for board-switch, or number/index */
 		if (!strncmp(this_opt, "panel:", 6)) {
@@ -1636,7 +1638,8 @@ static int au1200fb_setup(struct au1200fb_platdata *pd)
 			print_warn("Unsupported option \"%s\"", this_opt);
 	}
 
-out:
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 14/99] fbdev/au1200fb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/au1200fb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c
index 81c315454428..31a3f6afd8aa 100644
--- a/drivers/video/fbdev/au1200fb.c
+++ b/drivers/video/fbdev/au1200fb.c
@@ -31,6 +31,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/kernel.h>
@@ -1578,16 +1579,17 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
 static int au1200fb_setup(struct au1200fb_platdata *pd)
 {
 	char *options = NULL;
-	char *this_opt, *endptr;
+	struct option_iter iter;
+	const char *this_opt;
+	char *endptr;
 	int num_panels = ARRAY_SIZE(known_lcd_panels);
 	int panel_idx = -1;
 
 	fb_get_options(DRIVER_NAME, &options);
 
-	if (!options)
-		goto out;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		/* Panel option - can be panel name,
 		 * "bs" for board-switch, or number/index */
 		if (!strncmp(this_opt, "panel:", 6)) {
@@ -1636,7 +1638,8 @@ static int au1200fb_setup(struct au1200fb_platdata *pd)
 			print_warn("Unsupported option \"%s\"", this_opt);
 	}
 
-out:
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 15/99] fbdev/cirrusfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/cirrusfb.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index ba45e2147c52..fbf9281a7004 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -2336,10 +2336,20 @@ static int __init cirrusfb_setup(char *options)
 
 		if (!strcmp(this_opt, "noaccel"))
 			noaccel = 1;
-		else if (!strncmp(this_opt, "mode:", 5))
-			mode_option = this_opt + 5;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			if (!strncmp(this_opt, "mode:", 5))
+				this_opt += 5;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "cirrusfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "cirrusfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 15/99] fbdev/cirrusfb: Duplicate video-mode option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/cirrusfb.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index ba45e2147c52..fbf9281a7004 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -2336,10 +2336,20 @@ static int __init cirrusfb_setup(char *options)
 
 		if (!strcmp(this_opt, "noaccel"))
 			noaccel = 1;
-		else if (!strncmp(this_opt, "mode:", 5))
-			mode_option = this_opt + 5;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			if (!strncmp(this_opt, "mode:", 5))
+				this_opt += 5;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "cirrusfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "cirrusfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 16/99] fbdev/cirrusfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/cirrusfb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index fbf9281a7004..c6882bff3862 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -35,6 +35,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2323,17 +2324,14 @@ static struct zorro_driver cirrusfb_zorro_driver = {
 #endif /* CONFIG_ZORRO */
 
 #ifndef MODULE
-static int __init cirrusfb_setup(char *options)
+static int __init cirrusfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "noaccel"))
 			noaccel = 1;
 		else {
@@ -2351,6 +2349,9 @@ static int __init cirrusfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 16/99] fbdev/cirrusfb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/cirrusfb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index fbf9281a7004..c6882bff3862 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -35,6 +35,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2323,17 +2324,14 @@ static struct zorro_driver cirrusfb_zorro_driver = {
 #endif /* CONFIG_ZORRO */
 
 #ifndef MODULE
-static int __init cirrusfb_setup(char *options)
+static int __init cirrusfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "noaccel"))
 			noaccel = 1;
 		else {
@@ -2351,6 +2349,9 @@ static int __init cirrusfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 17/99] fbdev/controlfb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/controlfb.c | 34 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 77dbf94aae5f..82eeb139c4eb 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -113,14 +113,14 @@ struct fb_info_control {
 	struct fb_info		info;
 	struct fb_par_control	par;
 	u32			pseudo_palette[16];
-		
+
 	struct cmap_regs	__iomem *cmap_regs;
 	unsigned long		cmap_regs_phys;
-	
+
 	struct control_regs	__iomem *control_regs;
 	unsigned long		control_regs_phys;
 	unsigned long		control_regs_size;
-	
+
 	__u8			__iomem *frame_buffer;
 	unsigned long		frame_buffer_phys;
 	unsigned long		fb_orig_base;
@@ -196,7 +196,7 @@ static void set_control_clock(unsigned char *params)
 		while (!req.complete)
 			cuda_poll();
 	}
-#endif	
+#endif
 }
 
 /*
@@ -233,19 +233,19 @@ static void control_set_hardware(struct fb_info_control *p, struct fb_par_contro
 		if (p->par.xoffset != par->xoffset ||
 		    p->par.yoffset != par->yoffset)
 			set_screen_start(par->xoffset, par->yoffset, p);
-			
+
 		return;
 	}
-	
+
 	p->par = *par;
 	cmode = p->par.cmode;
 	r = &par->regvals;
-	
+
 	/* Turn off display */
 	out_le32(CNTRL_REG(p,ctrl), 0x400 | par->ctrl);
-	
+
 	set_control_clock(r->clock_params);
-	
+
 	RADACAL_WRITE(0x20, r->radacal_ctrl);
 	RADACAL_WRITE(0x21, p->control_use_bank2 ? 0 : 1);
 	RADACAL_WRITE(0x10, 0);
@@ -254,7 +254,7 @@ static void control_set_hardware(struct fb_info_control *p, struct fb_par_contro
 	rp = &p->control_regs->vswin;
 	for (i = 0; i < 16; ++i, ++rp)
 		out_le32(&rp->r, r->regs[i]);
-	
+
 	out_le32(CNTRL_REG(p,pitch), par->pitch);
 	out_le32(CNTRL_REG(p,mode), r->mode);
 	out_le32(CNTRL_REG(p,vram_attr), p->vram_attr);
@@ -366,7 +366,7 @@ static int read_control_sense(struct fb_info_control *p)
 	sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0x180) >> 7;
 
 	out_le32(CNTRL_REG(p,mon_sense), 077);	/* turn off drivers */
-	
+
 	return sense;
 }
 
@@ -558,9 +558,9 @@ static int control_var_to_par(struct fb_var_screeninfo *var,
 static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeninfo *var)
 {
 	struct control_regints *rv;
-	
+
 	rv = (struct control_regints *) par->regvals.regs;
-	
+
 	memset(var, 0, sizeof(*var));
 	var->xres = par->xres;
 	var->yres = par->yres;
@@ -568,7 +568,7 @@ static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeni
 	var->yres_virtual = par->vyres;
 	var->xoffset = par->xoffset;
 	var->yoffset = par->yoffset;
-	
+
 	switch(par->cmode) {
 	default:
 	case CMODE_8:
@@ -634,7 +634,7 @@ static int controlfb_check_var (struct fb_var_screeninfo *var, struct fb_info *i
 
 	err = control_var_to_par(var, &par, info);
 	if (err)
-		return err;	
+		return err;
 	control_par_to_var(&par, var);
 
 	return 0;
@@ -655,7 +655,7 @@ static int controlfb_set_par (struct fb_info *info)
 				 " control_var_to_par: %d.\n", err);
 		return err;
 	}
-	
+
 	control_set_hardware(p, &par);
 
 	info->fix.visual = (p->par.cmode == CMODE_8) ?
@@ -840,7 +840,7 @@ static int __init init_control(struct fb_info_control *p)
 	int full, sense, vmode, cmode, vyres;
 	struct fb_var_screeninfo var;
 	int rc;
-	
+
 	printk(KERN_INFO "controlfb: ");
 
 	full = p->total_vram == 0x400000;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 17/99] fbdev/controlfb: Remove trailing whitespaces
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/controlfb.c | 34 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 77dbf94aae5f..82eeb139c4eb 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -113,14 +113,14 @@ struct fb_info_control {
 	struct fb_info		info;
 	struct fb_par_control	par;
 	u32			pseudo_palette[16];
-		
+
 	struct cmap_regs	__iomem *cmap_regs;
 	unsigned long		cmap_regs_phys;
-	
+
 	struct control_regs	__iomem *control_regs;
 	unsigned long		control_regs_phys;
 	unsigned long		control_regs_size;
-	
+
 	__u8			__iomem *frame_buffer;
 	unsigned long		frame_buffer_phys;
 	unsigned long		fb_orig_base;
@@ -196,7 +196,7 @@ static void set_control_clock(unsigned char *params)
 		while (!req.complete)
 			cuda_poll();
 	}
-#endif	
+#endif
 }
 
 /*
@@ -233,19 +233,19 @@ static void control_set_hardware(struct fb_info_control *p, struct fb_par_contro
 		if (p->par.xoffset != par->xoffset ||
 		    p->par.yoffset != par->yoffset)
 			set_screen_start(par->xoffset, par->yoffset, p);
-			
+
 		return;
 	}
-	
+
 	p->par = *par;
 	cmode = p->par.cmode;
 	r = &par->regvals;
-	
+
 	/* Turn off display */
 	out_le32(CNTRL_REG(p,ctrl), 0x400 | par->ctrl);
-	
+
 	set_control_clock(r->clock_params);
-	
+
 	RADACAL_WRITE(0x20, r->radacal_ctrl);
 	RADACAL_WRITE(0x21, p->control_use_bank2 ? 0 : 1);
 	RADACAL_WRITE(0x10, 0);
@@ -254,7 +254,7 @@ static void control_set_hardware(struct fb_info_control *p, struct fb_par_contro
 	rp = &p->control_regs->vswin;
 	for (i = 0; i < 16; ++i, ++rp)
 		out_le32(&rp->r, r->regs[i]);
-	
+
 	out_le32(CNTRL_REG(p,pitch), par->pitch);
 	out_le32(CNTRL_REG(p,mode), r->mode);
 	out_le32(CNTRL_REG(p,vram_attr), p->vram_attr);
@@ -366,7 +366,7 @@ static int read_control_sense(struct fb_info_control *p)
 	sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0x180) >> 7;
 
 	out_le32(CNTRL_REG(p,mon_sense), 077);	/* turn off drivers */
-	
+
 	return sense;
 }
 
@@ -558,9 +558,9 @@ static int control_var_to_par(struct fb_var_screeninfo *var,
 static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeninfo *var)
 {
 	struct control_regints *rv;
-	
+
 	rv = (struct control_regints *) par->regvals.regs;
-	
+
 	memset(var, 0, sizeof(*var));
 	var->xres = par->xres;
 	var->yres = par->yres;
@@ -568,7 +568,7 @@ static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeni
 	var->yres_virtual = par->vyres;
 	var->xoffset = par->xoffset;
 	var->yoffset = par->yoffset;
-	
+
 	switch(par->cmode) {
 	default:
 	case CMODE_8:
@@ -634,7 +634,7 @@ static int controlfb_check_var (struct fb_var_screeninfo *var, struct fb_info *i
 
 	err = control_var_to_par(var, &par, info);
 	if (err)
-		return err;	
+		return err;
 	control_par_to_var(&par, var);
 
 	return 0;
@@ -655,7 +655,7 @@ static int controlfb_set_par (struct fb_info *info)
 				 " control_var_to_par: %d.\n", err);
 		return err;
 	}
-	
+
 	control_set_hardware(p, &par);
 
 	info->fix.visual = (p->par.cmode == CMODE_8) ?
@@ -840,7 +840,7 @@ static int __init init_control(struct fb_info_control *p)
 	int full, sense, vmode, cmode, vyres;
 	struct fb_var_screeninfo var;
 	int rc;
-	
+
 	printk(KERN_INFO "controlfb: ");
 
 	full = p->total_vram == 0x400000;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 18/99] fbdev/controlfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/controlfb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 82eeb139c4eb..3633e874ab2e 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -31,6 +31,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
@@ -795,14 +796,14 @@ static void __init control_init_info(struct fb_info *info, struct fb_info_contro
 /*
  * Parse user specified options (`video=controlfb:')
  */
-static void __init control_setup(char *options)
+static void __init control_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "vmode:", 6)) {
 			int vmode = simple_strtoul(this_opt+6, NULL, 0);
 			if (vmode > 0 && vmode <= VMODE_MAX &&
@@ -830,6 +831,8 @@ static void __init control_setup(char *options)
 			}
 		}
 	}
+
+	option_iter_release(&iter);
 }
 
 /*
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 18/99] fbdev/controlfb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/controlfb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 82eeb139c4eb..3633e874ab2e 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -31,6 +31,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
@@ -795,14 +796,14 @@ static void __init control_init_info(struct fb_info *info, struct fb_info_contro
 /*
  * Parse user specified options (`video=controlfb:')
  */
-static void __init control_setup(char *options)
+static void __init control_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "vmode:", 6)) {
 			int vmode = simple_strtoul(this_opt+6, NULL, 0);
 			if (vmode > 0 && vmode <= VMODE_MAX &&
@@ -830,6 +831,8 @@ static void __init control_setup(char *options)
 			}
 		}
 	}
+
+	option_iter_release(&iter);
 }
 
 /*
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 19/99] fbdev/cyber2000fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/cyber2000fb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/cyber2000fb.c b/drivers/video/fbdev/cyber2000fb.c
index 38c0a6866d76..939dde664b53 100644
--- a/drivers/video/fbdev/cyber2000fb.c
+++ b/drivers/video/fbdev/cyber2000fb.c
@@ -34,6 +34,7 @@
  * entering standby mode.)
  */
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1486,17 +1487,14 @@ static void cyberpro_free_fb_info(struct cfb_info *cfb)
  *  video=cyber2000:font:fontname
  */
 #ifndef MODULE
-static int cyber2000fb_setup(char *options)
+static int cyber2000fb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, opt)) {
 		if (strncmp(opt, "font:", 5) == 0) {
 			static char default_font_storage[40];
 
@@ -1508,6 +1506,9 @@ static int cyber2000fb_setup(char *options)
 
 		printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 19/99] fbdev/cyber2000fb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/cyber2000fb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/cyber2000fb.c b/drivers/video/fbdev/cyber2000fb.c
index 38c0a6866d76..939dde664b53 100644
--- a/drivers/video/fbdev/cyber2000fb.c
+++ b/drivers/video/fbdev/cyber2000fb.c
@@ -34,6 +34,7 @@
  * entering standby mode.)
  */
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1486,17 +1487,14 @@ static void cyberpro_free_fb_info(struct cfb_info *cfb)
  *  video=cyber2000:font:fontname
  */
 #ifndef MODULE
-static int cyber2000fb_setup(char *options)
+static int cyber2000fb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, opt)) {
 		if (strncmp(opt, "font:", 5) == 0) {
 			static char default_font_storage[40];
 
@@ -1508,6 +1506,9 @@ static int cyber2000fb_setup(char *options)
 
 		printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 20/99] fbdev/efifb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/efifb.c | 46 +++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index a5779fb453a2..1ae7574aaa82 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -8,6 +8,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/efi.h>
 #include <linux/efi-bgrt.h>
@@ -284,31 +285,32 @@ static const struct fb_ops efifb_ops = {
 	.fb_imageblit	= cfb_imageblit,
 };
 
-static int efifb_setup(char *options)
+static int efifb_setup(const char *options)
 {
-	char *this_opt;
-
-	if (options && *options) {
-		while ((this_opt = strsep(&options, ",")) != NULL) {
-			if (!*this_opt) continue;
-
-			efifb_setup_from_dmi(&screen_info, this_opt);
-
-			if (!strncmp(this_opt, "base:", 5))
-				screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
-			else if (!strncmp(this_opt, "stride:", 7))
-				screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
-			else if (!strncmp(this_opt, "height:", 7))
-				screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
-			else if (!strncmp(this_opt, "width:", 6))
-				screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
-			else if (!strcmp(this_opt, "nowc"))
-				mem_flags &= ~EFI_MEMORY_WC;
-			else if (!strcmp(this_opt, "nobgrt"))
-				use_bgrt = false;
-		}
+	struct option_iter iter;
+	const char *this_opt;
+
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
+		efifb_setup_from_dmi(&screen_info, this_opt);
+
+		if (!strncmp(this_opt, "base:", 5))
+			screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
+		else if (!strncmp(this_opt, "stride:", 7))
+			screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
+		else if (!strncmp(this_opt, "height:", 7))
+			screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
+		else if (!strncmp(this_opt, "width:", 6))
+			screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
+		else if (!strcmp(this_opt, "nowc"))
+			mem_flags &= ~EFI_MEMORY_WC;
+		else if (!strcmp(this_opt, "nobgrt"))
+			use_bgrt = false;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 20/99] fbdev/efifb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/efifb.c | 46 +++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index a5779fb453a2..1ae7574aaa82 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -8,6 +8,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/efi.h>
 #include <linux/efi-bgrt.h>
@@ -284,31 +285,32 @@ static const struct fb_ops efifb_ops = {
 	.fb_imageblit	= cfb_imageblit,
 };
 
-static int efifb_setup(char *options)
+static int efifb_setup(const char *options)
 {
-	char *this_opt;
-
-	if (options && *options) {
-		while ((this_opt = strsep(&options, ",")) != NULL) {
-			if (!*this_opt) continue;
-
-			efifb_setup_from_dmi(&screen_info, this_opt);
-
-			if (!strncmp(this_opt, "base:", 5))
-				screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
-			else if (!strncmp(this_opt, "stride:", 7))
-				screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
-			else if (!strncmp(this_opt, "height:", 7))
-				screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
-			else if (!strncmp(this_opt, "width:", 6))
-				screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
-			else if (!strcmp(this_opt, "nowc"))
-				mem_flags &= ~EFI_MEMORY_WC;
-			else if (!strcmp(this_opt, "nobgrt"))
-				use_bgrt = false;
-		}
+	struct option_iter iter;
+	const char *this_opt;
+
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
+		efifb_setup_from_dmi(&screen_info, this_opt);
+
+		if (!strncmp(this_opt, "base:", 5))
+			screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
+		else if (!strncmp(this_opt, "stride:", 7))
+			screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
+		else if (!strncmp(this_opt, "height:", 7))
+			screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
+		else if (!strncmp(this_opt, "width:", 6))
+			screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
+		else if (!strcmp(this_opt, "nowc"))
+			mem_flags &= ~EFI_MEMORY_WC;
+		else if (!strcmp(this_opt, "nobgrt"))
+			use_bgrt = false;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 21/99] fbdev/fm2fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fm2fb.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/fm2fb.c b/drivers/video/fbdev/fm2fb.c
index 942e382cf1cf..4f17bc8e6c1d 100644
--- a/drivers/video/fbdev/fm2fb.c
+++ b/drivers/video/fbdev/fm2fb.c
@@ -14,6 +14,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/fb.h>
@@ -293,19 +294,22 @@ static int fm2fb_probe(struct zorro_dev *z, const struct zorro_device_id *id)
 	return 0;
 }
 
-static int __init fm2fb_setup(char *options)
+static int __init fm2fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "pal", 3))
 			fm2fb_mode = FM2FB_MODE_PAL;
 		else if (!strncmp(this_opt, "ntsc", 4))
 			fm2fb_mode = FM2FB_MODE_NTSC;
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 21/99] fbdev/fm2fb: Parse option string with struct option_iter
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fm2fb.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/fm2fb.c b/drivers/video/fbdev/fm2fb.c
index 942e382cf1cf..4f17bc8e6c1d 100644
--- a/drivers/video/fbdev/fm2fb.c
+++ b/drivers/video/fbdev/fm2fb.c
@@ -14,6 +14,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/fb.h>
@@ -293,19 +294,22 @@ static int fm2fb_probe(struct zorro_dev *z, const struct zorro_device_id *id)
 	return 0;
 }
 
-static int __init fm2fb_setup(char *options)
+static int __init fm2fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "pal", 3))
 			fm2fb_mode = FM2FB_MODE_PAL;
 		else if (!strncmp(this_opt, "ntsc", 4))
 			fm2fb_mode = FM2FB_MODE_NTSC;
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:58   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fsl-diu-fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index e332017c6af6..e01281959062 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -1858,8 +1858,17 @@ static int __init fsl_diu_setup(char *options)
 		} else if (!strncmp(opt, "bpp=", 4)) {
 			if (!kstrtoul(opt + 4, 10, &val))
 				default_bpp = val;
-		} else
-			fb_mode = opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "fsl-diu-fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "fsl-diu-fb: option too long\n"))
+				continue;
+			fb_mode = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
@ 2023-03-06 15:58   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:58 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fsl-diu-fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index e332017c6af6..e01281959062 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -1858,8 +1858,17 @@ static int __init fsl_diu_setup(char *options)
 		} else if (!strncmp(opt, "bpp=", 4)) {
 			if (!kstrtoul(opt + 4, 10, &val))
 				default_bpp = val;
-		} else
-			fb_mode = opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "fsl-diu-fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "fsl-diu-fb: option too long\n"))
+				continue;
+			fb_mode = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 23/99] fbdev/fsl-diu-fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fsl-diu-fb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index e01281959062..c97a9c04e8e8 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -12,6 +12,7 @@
  *   Based on imxfb.c Copyright (C) 2004 S.Hauer, Pengutronix
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1842,17 +1843,15 @@ static int fsl_diu_remove(struct platform_device *pdev)
 }
 
 #ifndef MODULE
-static int __init fsl_diu_setup(char *options)
+static int __init fsl_diu_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 	unsigned long val;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	while (option_iter_next(&iter, opt)) {
 		if (!strncmp(opt, "monitor=", 8)) {
 			monitor_port = fsl_diu_name_to_port(opt + 8);
 		} else if (!strncmp(opt, "bpp=", 4)) {
@@ -1871,6 +1870,8 @@ static int __init fsl_diu_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 23/99] fbdev/fsl-diu-fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fsl-diu-fb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index e01281959062..c97a9c04e8e8 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -12,6 +12,7 @@
  *   Based on imxfb.c Copyright (C) 2004 S.Hauer, Pengutronix
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1842,17 +1843,15 @@ static int fsl_diu_remove(struct platform_device *pdev)
 }
 
 #ifndef MODULE
-static int __init fsl_diu_setup(char *options)
+static int __init fsl_diu_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 	unsigned long val;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	while (option_iter_next(&iter, opt)) {
 		if (!strncmp(opt, "monitor=", 8)) {
 			monitor_port = fsl_diu_name_to_port(opt + 8);
 		} else if (!strncmp(opt, "bpp=", 4)) {
@@ -1871,6 +1870,8 @@ static int __init fsl_diu_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 24/99] fbdev/gbefb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. Allocate the
copy's memory with devm_kstrdup(), as the driver parses the option string
once per probed device. Linux will automatically free the memory upon
releasing the device.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/gbefb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 000b4aa44241..5330aa6029ca 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1083,7 +1083,7 @@ ATTRIBUTE_GROUPS(gbefb);
  * Initialization
  */
 
-static int gbefb_setup(char *options)
+static int gbefb_setup(char *options, struct device *dev)
 {
 	char *this_opt;
 
@@ -1108,8 +1108,9 @@ static int gbefb_setup(char *options)
 				gbe_mem_size = CONFIG_FB_GBE_MEM * 1024 * 1024;
 			if (gbe_mem_size < TILE_SIZE)
 				gbe_mem_size = TILE_SIZE;
-		} else
-			mode_option = this_opt;
+		} else {
+			mode_option = devm_kstrdup(dev, this_opt, GFP_KERNEL);
+		}
 	}
 	return 0;
 }
@@ -1132,7 +1133,7 @@ static int gbefb_probe(struct platform_device *p_dev)
 		ret = -ENODEV;
 		goto out_release_framebuffer;
 	}
-	gbefb_setup(options);
+	gbefb_setup(options, &p_dev->dev);
 #endif
 
 	if (!request_mem_region(GBE_BASE, sizeof(struct sgi_gbe), "GBE")) {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 24/99] fbdev/gbefb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. Allocate the
copy's memory with devm_kstrdup(), as the driver parses the option string
once per probed device. Linux will automatically free the memory upon
releasing the device.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/gbefb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 000b4aa44241..5330aa6029ca 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1083,7 +1083,7 @@ ATTRIBUTE_GROUPS(gbefb);
  * Initialization
  */
 
-static int gbefb_setup(char *options)
+static int gbefb_setup(char *options, struct device *dev)
 {
 	char *this_opt;
 
@@ -1108,8 +1108,9 @@ static int gbefb_setup(char *options)
 				gbe_mem_size = CONFIG_FB_GBE_MEM * 1024 * 1024;
 			if (gbe_mem_size < TILE_SIZE)
 				gbe_mem_size = TILE_SIZE;
-		} else
-			mode_option = this_opt;
+		} else {
+			mode_option = devm_kstrdup(dev, this_opt, GFP_KERNEL);
+		}
 	}
 	return 0;
 }
@@ -1132,7 +1133,7 @@ static int gbefb_probe(struct platform_device *p_dev)
 		ret = -ENODEV;
 		goto out_release_framebuffer;
 	}
-	gbefb_setup(options);
+	gbefb_setup(options, &p_dev->dev);
 #endif
 
 	if (!request_mem_region(GBE_BASE, sizeof(struct sgi_gbe), "GBE")) {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 25/99] fbdev/gbefb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/gbefb.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 5330aa6029ca..36651bb6006d 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -9,6 +9,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
@@ -1083,14 +1084,14 @@ ATTRIBUTE_GROUPS(gbefb);
  * Initialization
  */
 
-static int gbefb_setup(char *options, struct device *dev)
+static int gbefb_setup(const char *options, struct device *dev)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "monitor:", 8)) {
 			if (!strncmp(this_opt + 8, "crt", 3)) {
 				flat_panel_enabled = 0;
@@ -1103,7 +1104,7 @@ static int gbefb_setup(char *options, struct device *dev)
 				default_mode = &default_mode_LCD;
 			}
 		} else if (!strncmp(this_opt, "mem:", 4)) {
-			gbe_mem_size = memparse(this_opt + 4, &this_opt);
+			gbe_mem_size = memparse(this_opt + 4, NULL);
 			if (gbe_mem_size > CONFIG_FB_GBE_MEM * 1024 * 1024)
 				gbe_mem_size = CONFIG_FB_GBE_MEM * 1024 * 1024;
 			if (gbe_mem_size < TILE_SIZE)
@@ -1112,6 +1113,9 @@ static int gbefb_setup(char *options, struct device *dev)
 			mode_option = devm_kstrdup(dev, this_opt, GFP_KERNEL);
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 25/99] fbdev/gbefb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/gbefb.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 5330aa6029ca..36651bb6006d 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -9,6 +9,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
@@ -1083,14 +1084,14 @@ ATTRIBUTE_GROUPS(gbefb);
  * Initialization
  */
 
-static int gbefb_setup(char *options, struct device *dev)
+static int gbefb_setup(const char *options, struct device *dev)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "monitor:", 8)) {
 			if (!strncmp(this_opt + 8, "crt", 3)) {
 				flat_panel_enabled = 0;
@@ -1103,7 +1104,7 @@ static int gbefb_setup(char *options, struct device *dev)
 				default_mode = &default_mode_LCD;
 			}
 		} else if (!strncmp(this_opt, "mem:", 4)) {
-			gbe_mem_size = memparse(this_opt + 4, &this_opt);
+			gbe_mem_size = memparse(this_opt + 4, NULL);
 			if (gbe_mem_size > CONFIG_FB_GBE_MEM * 1024 * 1024)
 				gbe_mem_size = CONFIG_FB_GBE_MEM * 1024 * 1024;
 			if (gbe_mem_size < TILE_SIZE)
@@ -1112,6 +1113,9 @@ static int gbefb_setup(char *options, struct device *dev)
 			mode_option = devm_kstrdup(dev, this_opt, GFP_KERNEL);
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 26/99] fbdev/geode: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/geode/gxfb_core.c | 10 +++++++++-
 drivers/video/fbdev/geode/lxfb_core.c | 13 +++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index 8e05e76de075..3ed85d2d53e9 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -497,10 +497,18 @@ static int __init gxfb_setup(char *options)
 		return 0;
 
 	while ((opt = strsep(&options, ",")) != NULL) {
+		static char mode_option_buf[256];
+		int ret;
+
 		if (!*opt)
 			continue;
 
-		mode_option = opt;
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+		if (WARN(ret < 0, "gxfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "gxfb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
 	}
 
 	return 0;
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index 8130e9eee2b4..6e1e73a21bdb 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -635,8 +635,17 @@ static int __init lxfb_setup(char *options)
 			nopanel = 1;
 		else if (!strcmp(opt, "nocrt"))
 			nocrt = 1;
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "lxfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "lxfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 26/99] fbdev/geode: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/geode/gxfb_core.c | 10 +++++++++-
 drivers/video/fbdev/geode/lxfb_core.c | 13 +++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index 8e05e76de075..3ed85d2d53e9 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -497,10 +497,18 @@ static int __init gxfb_setup(char *options)
 		return 0;
 
 	while ((opt = strsep(&options, ",")) != NULL) {
+		static char mode_option_buf[256];
+		int ret;
+
 		if (!*opt)
 			continue;
 
-		mode_option = opt;
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+		if (WARN(ret < 0, "gxfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "gxfb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
 	}
 
 	return 0;
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index 8130e9eee2b4..6e1e73a21bdb 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -635,8 +635,17 @@ static int __init lxfb_setup(char *options)
 			nopanel = 1;
 		else if (!strcmp(opt, "nocrt"))
 			nocrt = 1;
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "lxfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "lxfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 27/99] fbdev/geode: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/geode/gx1fb_core.c | 16 ++++++++--------
 drivers/video/fbdev/geode/gxfb_core.c  | 17 ++++++++---------
 drivers/video/fbdev/geode/lxfb_core.c  | 14 ++++++--------
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/drivers/video/fbdev/geode/gx1fb_core.c b/drivers/video/fbdev/geode/gx1fb_core.c
index 9c942001ac10..dd1dc7ee7f83 100644
--- a/drivers/video/fbdev/geode/gx1fb_core.c
+++ b/drivers/video/fbdev/geode/gx1fb_core.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -403,17 +404,14 @@ static void gx1fb_remove(struct pci_dev *pdev)
 }
 
 #ifndef MODULE
-static void __init gx1fb_setup(char *options)
+static void __init gx1fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
-
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "mode:", 5))
 			strscpy(mode_option, this_opt + 5, sizeof(mode_option));
 		else if (!strncmp(this_opt, "crt:", 4))
@@ -423,6 +421,8 @@ static void __init gx1fb_setup(char *options)
 		else
 			strscpy(mode_option, this_opt, sizeof(mode_option));
 	}
+
+	option_iter_release(&iter);
 }
 #endif
 
diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index 3ed85d2d53e9..f5e88e92ba16 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -16,6 +16,7 @@
  * 16 MiB of framebuffer memory is assumed to be available.
  */
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -488,21 +489,17 @@ static struct pci_driver gxfb_driver = {
 };
 
 #ifndef MODULE
-static int __init gxfb_setup(char *options)
+static int __init gxfb_setup(const char *options)
 {
+	struct option_iter iter;
+	const char *opt;
 
-	char *opt;
+	option_iter_init(&iter, options);
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
-		if (!*opt)
-			continue;
-
 		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
 		if (WARN(ret < 0, "gxfb: ignoring invalid option, ret=%d\n", ret))
 			continue;
@@ -511,6 +508,8 @@ static int __init gxfb_setup(char *options)
 		mode_option = mode_option_buf;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index 6e1e73a21bdb..d687054cdb09 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -618,17 +619,14 @@ static struct pci_driver lxfb_driver = {
 };
 
 #ifndef MODULE
-static int __init lxfb_setup(char *options)
+static int __init lxfb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, opt)) {
 		if (!strcmp(opt, "noclear"))
 			noclear = 1;
 		else if (!strcmp(opt, "nopanel"))
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 27/99] fbdev/geode: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/geode/gx1fb_core.c | 16 ++++++++--------
 drivers/video/fbdev/geode/gxfb_core.c  | 17 ++++++++---------
 drivers/video/fbdev/geode/lxfb_core.c  | 14 ++++++--------
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/drivers/video/fbdev/geode/gx1fb_core.c b/drivers/video/fbdev/geode/gx1fb_core.c
index 9c942001ac10..dd1dc7ee7f83 100644
--- a/drivers/video/fbdev/geode/gx1fb_core.c
+++ b/drivers/video/fbdev/geode/gx1fb_core.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -403,17 +404,14 @@ static void gx1fb_remove(struct pci_dev *pdev)
 }
 
 #ifndef MODULE
-static void __init gx1fb_setup(char *options)
+static void __init gx1fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
-
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "mode:", 5))
 			strscpy(mode_option, this_opt + 5, sizeof(mode_option));
 		else if (!strncmp(this_opt, "crt:", 4))
@@ -423,6 +421,8 @@ static void __init gx1fb_setup(char *options)
 		else
 			strscpy(mode_option, this_opt, sizeof(mode_option));
 	}
+
+	option_iter_release(&iter);
 }
 #endif
 
diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index 3ed85d2d53e9..f5e88e92ba16 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -16,6 +16,7 @@
  * 16 MiB of framebuffer memory is assumed to be available.
  */
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -488,21 +489,17 @@ static struct pci_driver gxfb_driver = {
 };
 
 #ifndef MODULE
-static int __init gxfb_setup(char *options)
+static int __init gxfb_setup(const char *options)
 {
+	struct option_iter iter;
+	const char *opt;
 
-	char *opt;
+	option_iter_init(&iter, options);
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
-		if (!*opt)
-			continue;
-
 		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
 		if (WARN(ret < 0, "gxfb: ignoring invalid option, ret=%d\n", ret))
 			continue;
@@ -511,6 +508,8 @@ static int __init gxfb_setup(char *options)
 		mode_option = mode_option_buf;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index 6e1e73a21bdb..d687054cdb09 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -618,17 +619,14 @@ static struct pci_driver lxfb_driver = {
 };
 
 #ifndef MODULE
-static int __init lxfb_setup(char *options)
+static int __init lxfb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, opt)) {
 		if (!strcmp(opt, "noclear"))
 			noclear = 1;
 		else if (!strcmp(opt, "nopanel"))
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 28/99] fbdev/grvga: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/grvga.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index 24818b276241..bb4baec2eccc 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -369,8 +369,20 @@ static int grvga_probe(struct platform_device *dev)
 			grvga_fix_addr = simple_strtoul(this_opt + 5, NULL, 16);
 		else if (!strncmp(this_opt, "size", 4))
 			grvga_mem_size = simple_strtoul(this_opt + 5, NULL, 0);
-		else
-			mode_opt = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0,
+				 "grlib-svgactrl: ignoring invalid option, ret=%d\n",
+				 ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf),
+				 "grlib-svgactrl: option too long\n"))
+				continue;
+			mode_opt = mode_option_buf;
+		}
 	}
 
 	par = info->par;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 28/99] fbdev/grvga: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/grvga.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index 24818b276241..bb4baec2eccc 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -369,8 +369,20 @@ static int grvga_probe(struct platform_device *dev)
 			grvga_fix_addr = simple_strtoul(this_opt + 5, NULL, 16);
 		else if (!strncmp(this_opt, "size", 4))
 			grvga_mem_size = simple_strtoul(this_opt + 5, NULL, 0);
-		else
-			mode_opt = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0,
+				 "grlib-svgactrl: ignoring invalid option, ret=%d\n",
+				 ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf),
+				 "grlib-svgactrl: option too long\n"))
+				continue;
+			mode_opt = mode_option_buf;
+		}
 	}
 
 	par = info->par;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/grvga.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index bb4baec2eccc..f803dc37c891 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -10,6 +10,7 @@
  * Contributors: Kristoffer Glembo <kristoffer@gaisler.com>
  */
 
+#include <linux/cmdline.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/of_platform.h>
@@ -334,6 +335,8 @@ static int grvga_probe(struct platform_device *dev)
 	unsigned long grvga_mem_size = 0;
 	struct grvga_par *par = NULL;
 	char *options = NULL, *mode_opt = NULL;
+	struct option_iter iter;
+	const char *this_opt;
 
 	info = framebuffer_alloc(sizeof(struct grvga_par), &dev->dev);
 	if (!info)
@@ -353,15 +356,13 @@ static int grvga_probe(struct platform_device *dev)
 	if (!options || !*options)
 		options =  "640x480-8@60";
 
-	while (1) {
-		char *this_opt = strsep(&options, ",");
-
-		if (!this_opt)
-			break;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "custom", 6)) {
 			if (grvga_parse_custom(this_opt, &info->var) < 0) {
 				dev_err(&dev->dev, "Failed to parse custom mode (%s).\n", this_opt);
+				option_iter_release(&iter);
 				retval = -EINVAL;
 				goto free_fb;
 			}
@@ -385,6 +386,8 @@ static int grvga_probe(struct platform_device *dev)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	par = info->par;
 	info->fbops = &grvga_ops;
 	info->fix = grvga_fix;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/grvga.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index bb4baec2eccc..f803dc37c891 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -10,6 +10,7 @@
  * Contributors: Kristoffer Glembo <kristoffer@gaisler.com>
  */
 
+#include <linux/cmdline.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/of_platform.h>
@@ -334,6 +335,8 @@ static int grvga_probe(struct platform_device *dev)
 	unsigned long grvga_mem_size = 0;
 	struct grvga_par *par = NULL;
 	char *options = NULL, *mode_opt = NULL;
+	struct option_iter iter;
+	const char *this_opt;
 
 	info = framebuffer_alloc(sizeof(struct grvga_par), &dev->dev);
 	if (!info)
@@ -353,15 +356,13 @@ static int grvga_probe(struct platform_device *dev)
 	if (!options || !*options)
 		options =  "640x480-8@60";
 
-	while (1) {
-		char *this_opt = strsep(&options, ",");
-
-		if (!this_opt)
-			break;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "custom", 6)) {
 			if (grvga_parse_custom(this_opt, &info->var) < 0) {
 				dev_err(&dev->dev, "Failed to parse custom mode (%s).\n", this_opt);
+				option_iter_release(&iter);
 				retval = -EINVAL;
 				goto free_fb;
 			}
@@ -385,6 +386,8 @@ static int grvga_probe(struct platform_device *dev)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	par = info->par;
 	info->fbops = &grvga_ops;
 	info->fix = grvga_fix;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 30/99] fbdev/gxt4500: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/gxt4500.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/gxt4500.c b/drivers/video/fbdev/gxt4500.c
index 5f42d3d9d6ce..61bc714693f5 100644
--- a/drivers/video/fbdev/gxt4500.c
+++ b/drivers/video/fbdev/gxt4500.c
@@ -779,12 +779,28 @@ static struct pci_driver gxt4500_driver = {
 
 static int gxt4500_init(void)
 {
+#ifndef MODULE
+	char *options;
+#endif
+
 	if (fb_modesetting_disabled("gxt4500"))
 		return -ENODEV;
 
 #ifndef MODULE
-	if (fb_get_options("gxt4500", &mode_option))
+	if (fb_get_options("gxt4500", &options))
 		return -ENODEV;
+
+	do {
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", options);
+		if (WARN(ret < 0, "gxt4500: ignoring invalid option, ret=%d\n", ret))
+			break;
+		if (WARN(ret >= sizeof(mode_option_buf), "gxt4500: option too long\n"))
+			break;
+		mode_option = mode_option_buf;
+	} while (0);
 #endif
 
 	return pci_register_driver(&gxt4500_driver);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 30/99] fbdev/gxt4500: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/gxt4500.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/gxt4500.c b/drivers/video/fbdev/gxt4500.c
index 5f42d3d9d6ce..61bc714693f5 100644
--- a/drivers/video/fbdev/gxt4500.c
+++ b/drivers/video/fbdev/gxt4500.c
@@ -779,12 +779,28 @@ static struct pci_driver gxt4500_driver = {
 
 static int gxt4500_init(void)
 {
+#ifndef MODULE
+	char *options;
+#endif
+
 	if (fb_modesetting_disabled("gxt4500"))
 		return -ENODEV;
 
 #ifndef MODULE
-	if (fb_get_options("gxt4500", &mode_option))
+	if (fb_get_options("gxt4500", &options))
 		return -ENODEV;
+
+	do {
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", options);
+		if (WARN(ret < 0, "gxt4500: ignoring invalid option, ret=%d\n", ret))
+			break;
+		if (WARN(ret >= sizeof(mode_option_buf), "gxt4500: option too long\n"))
+			break;
+		mode_option = mode_option_buf;
+	} while (0);
 #endif
 
 	return pci_register_driver(&gxt4500_driver);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 31/99] fbdev/hyperv_fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. As the driver
implements a very simple mode parser in a fairly unstructured way, just
duplicate the option string and parse the duplicated memory buffer. Free
the buffer afterwards.

Done in preparation of constifying the option string and switching the
driver to struct option_iter.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/hyperv_fb.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
index 4a6a3303b6b4..edb0555239c6 100644
--- a/drivers/video/fbdev/hyperv_fb.c
+++ b/drivers/video/fbdev/hyperv_fb.c
@@ -903,17 +903,23 @@ static const struct fb_ops hvfb_ops = {
 static void hvfb_get_option(struct fb_info *info)
 {
 	struct hvfb_par *par = info->par;
-	char *opt = NULL, *p;
+	char *options = NULL;
+	char *optbuf, *opt, *p;
 	uint x = 0, y = 0;
 
-	if (fb_get_options(KBUILD_MODNAME, &opt) || !opt || !*opt)
+	if (fb_get_options(KBUILD_MODNAME, &options) || !options || !*options)
 		return;
 
+	optbuf = kstrdup(options, GFP_KERNEL);
+	if (!optbuf)
+		return;
+	opt = optbuf;
+
 	p = strsep(&opt, "x");
 	if (!*p || kstrtouint(p, 0, &x) ||
 	    !opt || !*opt || kstrtouint(opt, 0, &y)) {
 		pr_err("Screen option is invalid: skipped\n");
-		return;
+		goto out;
 	}
 
 	if (x < HVFB_WIDTH_MIN || y < HVFB_HEIGHT_MIN ||
@@ -922,12 +928,14 @@ static void hvfb_get_option(struct fb_info *info)
 	    (par->synthvid_version == SYNTHVID_VERSION_WIN8 &&
 	     x * y * screen_depth / 8 > SYNTHVID_FB_SIZE_WIN8)) {
 		pr_err("Screen resolution option is out of range: skipped\n");
-		return;
+		goto out;
 	}
 
 	screen_width = x;
 	screen_height = y;
-	return;
+
+out:
+	kfree(optbuf);
 }
 
 /*
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 31/99] fbdev/hyperv_fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. As the driver
implements a very simple mode parser in a fairly unstructured way, just
duplicate the option string and parse the duplicated memory buffer. Free
the buffer afterwards.

Done in preparation of constifying the option string and switching the
driver to struct option_iter.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/hyperv_fb.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
index 4a6a3303b6b4..edb0555239c6 100644
--- a/drivers/video/fbdev/hyperv_fb.c
+++ b/drivers/video/fbdev/hyperv_fb.c
@@ -903,17 +903,23 @@ static const struct fb_ops hvfb_ops = {
 static void hvfb_get_option(struct fb_info *info)
 {
 	struct hvfb_par *par = info->par;
-	char *opt = NULL, *p;
+	char *options = NULL;
+	char *optbuf, *opt, *p;
 	uint x = 0, y = 0;
 
-	if (fb_get_options(KBUILD_MODNAME, &opt) || !opt || !*opt)
+	if (fb_get_options(KBUILD_MODNAME, &options) || !options || !*options)
 		return;
 
+	optbuf = kstrdup(options, GFP_KERNEL);
+	if (!optbuf)
+		return;
+	opt = optbuf;
+
 	p = strsep(&opt, "x");
 	if (!*p || kstrtouint(p, 0, &x) ||
 	    !opt || !*opt || kstrtouint(opt, 0, &y)) {
 		pr_err("Screen option is invalid: skipped\n");
-		return;
+		goto out;
 	}
 
 	if (x < HVFB_WIDTH_MIN || y < HVFB_HEIGHT_MIN ||
@@ -922,12 +928,14 @@ static void hvfb_get_option(struct fb_info *info)
 	    (par->synthvid_version == SYNTHVID_VERSION_WIN8 &&
 	     x * y * screen_depth / 8 > SYNTHVID_FB_SIZE_WIN8)) {
 		pr_err("Screen resolution option is out of range: skipped\n");
-		return;
+		goto out;
 	}
 
 	screen_width = x;
 	screen_height = y;
-	return;
+
+out:
+	kfree(optbuf);
 }
 
 /*
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 32/99] fbdev/i740fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i740fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c
index 3860b137b86a..dd4b5c717e8e 100644
--- a/drivers/video/fbdev/i740fb.c
+++ b/drivers/video/fbdev/i740fb.c
@@ -1273,8 +1273,17 @@ static int  __init i740fb_setup(char *options)
 			continue;
 		else if (!strncmp(opt, "mtrr:", 5))
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "i740fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "i740fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 32/99] fbdev/i740fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i740fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c
index 3860b137b86a..dd4b5c717e8e 100644
--- a/drivers/video/fbdev/i740fb.c
+++ b/drivers/video/fbdev/i740fb.c
@@ -1273,8 +1273,17 @@ static int  __init i740fb_setup(char *options)
 			continue;
 		else if (!strncmp(opt, "mtrr:", 5))
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "i740fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "i740fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 33/99] fbdev/i740fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i740fb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c
index dd4b5c717e8e..cf45d6280f38 100644
--- a/drivers/video/fbdev/i740fb.c
+++ b/drivers/video/fbdev/i740fb.c
@@ -13,6 +13,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1261,17 +1262,15 @@ static struct pci_driver i740fb_driver = {
 };
 
 #ifndef MODULE
-static int  __init i740fb_setup(char *options)
+static int  __init i740fb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
-		else if (!strncmp(opt, "mtrr:", 5))
+	while (option_iter_next(&iter, opt)) {
+		if (!strncmp(opt, "mtrr:", 5))
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
 		else {
 			static char mode_option_buf[256];
@@ -1286,6 +1285,8 @@ static int  __init i740fb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 33/99] fbdev/i740fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i740fb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c
index dd4b5c717e8e..cf45d6280f38 100644
--- a/drivers/video/fbdev/i740fb.c
+++ b/drivers/video/fbdev/i740fb.c
@@ -13,6 +13,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1261,17 +1262,15 @@ static struct pci_driver i740fb_driver = {
 };
 
 #ifndef MODULE
-static int  __init i740fb_setup(char *options)
+static int  __init i740fb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
-		else if (!strncmp(opt, "mtrr:", 5))
+	while (option_iter_next(&iter, opt)) {
+		if (!strncmp(opt, "mtrr:", 5))
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
 		else {
 			static char mode_option_buf[256];
@@ -1286,6 +1285,8 @@ static int  __init i740fb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 34/99] fbdev/i810: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i810/i810_main.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c
index 85abb65f07d7..66f94dfaef16 100644
--- a/drivers/video/fbdev/i810/i810_main.c
+++ b/drivers/video/fbdev/i810/i810_main.c
@@ -2002,8 +2002,17 @@ static int i810fb_setup(char *options)
 			dcolor = true;
 		else if (!strncmp(this_opt, "ddc3", 4))
 			ddc3 = true;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "i810fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "i810fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 34/99] fbdev/i810: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i810/i810_main.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c
index 85abb65f07d7..66f94dfaef16 100644
--- a/drivers/video/fbdev/i810/i810_main.c
+++ b/drivers/video/fbdev/i810/i810_main.c
@@ -2002,8 +2002,17 @@ static int i810fb_setup(char *options)
 			dcolor = true;
 		else if (!strncmp(this_opt, "ddc3", 4))
 			ddc3 = true;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "i810fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "i810fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 35/99] fbdev/i810: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i810/i810_main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c
index 66f94dfaef16..3e624522fe7a 100644
--- a/drivers/video/fbdev/i810/i810_main.c
+++ b/drivers/video/fbdev/i810/i810_main.c
@@ -29,6 +29,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1958,14 +1959,15 @@ static void i810fb_find_init_mode(struct fb_info *info)
 }
 
 #ifndef MODULE
-static int i810fb_setup(char *options)
+static int i810fb_setup(const char *options)
 {
-	char *this_opt, *suffix = NULL;
+	char *suffix = NULL;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "mtrr", 4))
 			mtrr = true;
 		else if (!strncmp(this_opt, "accel", 5))
@@ -2014,6 +2016,9 @@ static int i810fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 35/99] fbdev/i810: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/i810/i810_main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c
index 66f94dfaef16..3e624522fe7a 100644
--- a/drivers/video/fbdev/i810/i810_main.c
+++ b/drivers/video/fbdev/i810/i810_main.c
@@ -29,6 +29,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1958,14 +1959,15 @@ static void i810fb_find_init_mode(struct fb_info *info)
 }
 
 #ifndef MODULE
-static int i810fb_setup(char *options)
+static int i810fb_setup(const char *options)
 {
-	char *this_opt, *suffix = NULL;
+	char *suffix = NULL;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "mtrr", 4))
 			mtrr = true;
 		else if (!strncmp(this_opt, "accel", 5))
@@ -2014,6 +2016,9 @@ static int i810fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 36/99] fbdev/imsttfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/imsttfb.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
index bea45647184e..fc046886599c 100644
--- a/drivers/video/fbdev/imsttfb.c
+++ b/drivers/video/fbdev/imsttfb.c
@@ -17,6 +17,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1560,16 +1561,16 @@ static void imsttfb_remove(struct pci_dev *pdev)
 
 #ifndef MODULE
 static int __init
-imsttfb_setup(char *options)
+imsttfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "font:", 5)) {
-			char *p;
+			const char *p;
 			int i;
 
 			p = this_opt + 5;
@@ -1608,6 +1609,9 @@ imsttfb_setup(char *options)
 		}
 #endif
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 36/99] fbdev/imsttfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/imsttfb.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
index bea45647184e..fc046886599c 100644
--- a/drivers/video/fbdev/imsttfb.c
+++ b/drivers/video/fbdev/imsttfb.c
@@ -17,6 +17,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1560,16 +1561,16 @@ static void imsttfb_remove(struct pci_dev *pdev)
 
 #ifndef MODULE
 static int __init
-imsttfb_setup(char *options)
+imsttfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "font:", 5)) {
-			char *p;
+			const char *p;
 			int i;
 
 			p = this_opt + 5;
@@ -1608,6 +1609,9 @@ imsttfb_setup(char *options)
 		}
 #endif
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 37/99] fbdev/intelfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/intelfb/intelfbdrv.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 0a9e5067b201..896c2646e2ae 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -365,8 +365,17 @@ static int __init intelfb_setup(char *options)
 			noinit = !noinit;
 		else if (OPT_EQUAL(this_opt, "mode="))
 			mode = get_opt_string(this_opt, "mode=");
-		else
-			mode = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "intelfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "intelfb: option too long\n"))
+				continue;
+			mode = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 37/99] fbdev/intelfb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/intelfb/intelfbdrv.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 0a9e5067b201..896c2646e2ae 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -365,8 +365,17 @@ static int __init intelfb_setup(char *options)
 			noinit = !noinit;
 		else if (OPT_EQUAL(this_opt, "mode="))
 			mode = get_opt_string(this_opt, "mode=");
-		else
-			mode = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "intelfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "intelfb: option too long\n"))
+				continue;
+			mode = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 38/99] fbdev/intelfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/intelfb/intelfbdrv.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 896c2646e2ae..2d4e03b9e7fd 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -108,6 +108,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -323,9 +324,10 @@ static __inline__ int get_opt_bool(const char *this_opt, const char *name,
 	return 1;
 }
 
-static int __init intelfb_setup(char *options)
+static int __init intelfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	DBG_MSG("intelfb_setup\n");
 
@@ -348,9 +350,9 @@ static int __init intelfb_setup(char *options)
 	 *    video=intelfb:1024x768-16@75,accel=0
 	 */
 
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (get_opt_bool(this_opt, "accel", &accel))
 			;
 		else if (get_opt_int(this_opt, "vram", &vram))
@@ -378,6 +380,8 @@ static int __init intelfb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 38/99] fbdev/intelfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/intelfb/intelfbdrv.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 896c2646e2ae..2d4e03b9e7fd 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -108,6 +108,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -323,9 +324,10 @@ static __inline__ int get_opt_bool(const char *this_opt, const char *name,
 	return 1;
 }
 
-static int __init intelfb_setup(char *options)
+static int __init intelfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	DBG_MSG("intelfb_setup\n");
 
@@ -348,9 +350,9 @@ static int __init intelfb_setup(char *options)
 	 *    video=intelfb:1024x768-16@75,accel=0
 	 */
 
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (get_opt_bool(this_opt, "accel", &accel))
 			;
 		else if (get_opt_int(this_opt, "vram", &vram))
@@ -378,6 +380,8 @@ static int __init intelfb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 39/99] fbdev/imxfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/imxfb.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 51fde1b2a793..34cd4d4fd137 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -854,10 +854,18 @@ static int imxfb_setup(void)
 		return 0;
 
 	while ((opt = strsep(&options, ",")) != NULL) {
+		static char mode_option_buf[256];
+		int ret;
+
 		if (!*opt)
 			continue;
-		else
-			fb_mode = opt;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+		if (WARN(ret < 0, "imxfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "imxfb: option too long\n"))
+			continue;
+		fb_mode = mode_option_buf;
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 39/99] fbdev/imxfb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/imxfb.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 51fde1b2a793..34cd4d4fd137 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -854,10 +854,18 @@ static int imxfb_setup(void)
 		return 0;
 
 	while ((opt = strsep(&options, ",")) != NULL) {
+		static char mode_option_buf[256];
+		int ret;
+
 		if (!*opt)
 			continue;
-		else
-			fb_mode = opt;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+		if (WARN(ret < 0, "imxfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "imxfb: option too long\n"))
+			continue;
+		fb_mode = mode_option_buf;
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 40/99] fbdev/imxfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/imxfb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 34cd4d4fd137..950df484e5be 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -14,6 +14,7 @@
  *	linux-arm-kernel@lists.arm.linux.org.uk
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -845,21 +846,19 @@ static struct lcd_ops imxfb_lcd_ops = {
 
 static int imxfb_setup(void)
 {
-	char *opt, *options = NULL;
+	char *options = NULL;
+	struct option_iter iter;
+	const char *opt;
 
 	if (fb_get_options("imxfb", &options))
 		return -ENODEV;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
-		if (!*opt)
-			continue;
-
 		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
 		if (WARN(ret < 0, "imxfb: ignoring invalid option, ret=%d\n", ret))
 			continue;
@@ -868,6 +867,8 @@ static int imxfb_setup(void)
 		fb_mode = mode_option_buf;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 40/99] fbdev/imxfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/imxfb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 34cd4d4fd137..950df484e5be 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -14,6 +14,7 @@
  *	linux-arm-kernel@lists.arm.linux.org.uk
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -845,21 +846,19 @@ static struct lcd_ops imxfb_lcd_ops = {
 
 static int imxfb_setup(void)
 {
-	char *opt, *options = NULL;
+	char *options = NULL;
+	struct option_iter iter;
+	const char *opt;
 
 	if (fb_get_options("imxfb", &options))
 		return -ENODEV;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
-		if (!*opt)
-			continue;
-
 		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
 		if (WARN(ret < 0, "imxfb: ignoring invalid option, ret=%d\n", ret))
 			continue;
@@ -868,6 +867,8 @@ static int imxfb_setup(void)
 		fb_mode = mode_option_buf;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 41/99] fbdev/kyrofb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/kyro/fbdev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index 0596573ef140..a171f1119e4d 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -579,7 +579,15 @@ static int __init kyrofb_setup(char *options)
 		} else if (strcmp(this_opt, "nomtrr") == 0) {
 			nomtrr = 1;
 		} else {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "kyrofb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "kyrofb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		}
 	}
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 41/99] fbdev/kyrofb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/kyro/fbdev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index 0596573ef140..a171f1119e4d 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -579,7 +579,15 @@ static int __init kyrofb_setup(char *options)
 		} else if (strcmp(this_opt, "nomtrr") == 0) {
 			nomtrr = 1;
 		} else {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "kyrofb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "kyrofb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		}
 	}
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 42/99] fbdev/kyrofb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/kyro/fbdev.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index a171f1119e4d..c2c6e1bba3a0 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -562,16 +563,14 @@ static int kyrofb_setcolreg(u_int regno, u_int red, u_int green,
 }
 
 #ifndef MODULE
-static int __init kyrofb_setup(char *options)
+static int __init kyrofb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (strcmp(this_opt, "nopan") == 0) {
 			nopan = 1;
 		} else if (strcmp(this_opt, "nowrap") == 0) {
@@ -591,6 +590,8 @@ static int __init kyrofb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 42/99] fbdev/kyrofb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/kyro/fbdev.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index a171f1119e4d..c2c6e1bba3a0 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -562,16 +563,14 @@ static int kyrofb_setcolreg(u_int regno, u_int red, u_int green,
 }
 
 #ifndef MODULE
-static int __init kyrofb_setup(char *options)
+static int __init kyrofb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (strcmp(this_opt, "nopan") == 0) {
 			nopan = 1;
 		} else if (strcmp(this_opt, "nowrap") == 0) {
@@ -591,6 +590,8 @@ static int __init kyrofb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 43/99] fbdev/macfb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/macfb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index 312e35c9aa6c..44ff860a3f37 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -339,7 +339,7 @@ static int civic_setpalette(unsigned int regno, unsigned int red,
 {
 	unsigned long flags;
 	int clut_status;
-	
+
 	local_irq_save(flags);
 
 	/* Set the register address */
@@ -439,7 +439,7 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
 	 * (according to the entries in the `var' structure).
 	 * Return non-zero for invalid regno.
 	 */
-	
+
 	if (regno >= fb_info->cmap.len)
 		return 1;
 
@@ -548,7 +548,7 @@ static int __init macfb_init(void)
 		return -ENODEV;
 	macfb_setup(option);
 
-	if (!MACH_IS_MAC) 
+	if (!MACH_IS_MAC)
 		return -ENODEV;
 
 	if (mac_bi_data.id == MAC_MODEL_Q630 ||
@@ -644,7 +644,7 @@ static int __init macfb_init(void)
 		err = -EINVAL;
 		goto fail_unmap;
 	}
-	
+
 	/*
 	 * We take a wild guess that if the video physical address is
 	 * in nubus slot space, that the nubus card is driving video.
@@ -774,7 +774,7 @@ static int __init macfb_init(void)
 			civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
 			break;
 
-		
+
 		/*
 		 * Assorted weirdos
 		 * We think this may be like the LC II
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 43/99] fbdev/macfb: Remove trailing whitespaces
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/macfb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index 312e35c9aa6c..44ff860a3f37 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -339,7 +339,7 @@ static int civic_setpalette(unsigned int regno, unsigned int red,
 {
 	unsigned long flags;
 	int clut_status;
-	
+
 	local_irq_save(flags);
 
 	/* Set the register address */
@@ -439,7 +439,7 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
 	 * (according to the entries in the `var' structure).
 	 * Return non-zero for invalid regno.
 	 */
-	
+
 	if (regno >= fb_info->cmap.len)
 		return 1;
 
@@ -548,7 +548,7 @@ static int __init macfb_init(void)
 		return -ENODEV;
 	macfb_setup(option);
 
-	if (!MACH_IS_MAC) 
+	if (!MACH_IS_MAC)
 		return -ENODEV;
 
 	if (mac_bi_data.id == MAC_MODEL_Q630 ||
@@ -644,7 +644,7 @@ static int __init macfb_init(void)
 		err = -EINVAL;
 		goto fail_unmap;
 	}
-	
+
 	/*
 	 * We take a wild guess that if the video physical address is
 	 * in nubus slot space, that the nubus card is driving video.
@@ -774,7 +774,7 @@ static int __init macfb_init(void)
 			civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
 			break;
 
-		
+
 		/*
 		 * Assorted weirdos
 		 * We think this may be like the LC II
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 44/99] fbdev/macfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/macfb.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index 44ff860a3f37..a72edb98b170 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -20,6 +20,7 @@
  * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -504,23 +505,22 @@ static const struct fb_ops macfb_ops = {
 	.fb_imageblit	= cfb_imageblit,
 };
 
-static void __init macfb_setup(char *options)
+static void __init macfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "inverse"))
 			fb_invert_cmaps();
 		else
 			if (!strcmp(this_opt, "vidtest"))
 				vidtest = 1; /* enable experimental CLUT code */
 	}
+
+	option_iter_release(&iter);
 }
 
 static void __init iounmap_macfb(void)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 44/99] fbdev/macfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/macfb.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index 44ff860a3f37..a72edb98b170 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -20,6 +20,7 @@
  * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -504,23 +505,22 @@ static const struct fb_ops macfb_ops = {
 	.fb_imageblit	= cfb_imageblit,
 };
 
-static void __init macfb_setup(char *options)
+static void __init macfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "inverse"))
 			fb_invert_cmaps();
 		else
 			if (!strcmp(this_opt, "vidtest"))
 				vidtest = 1; /* enable experimental CLUT code */
 	}
+
+	option_iter_release(&iter);
 }
 
 static void __init iounmap_macfb(void)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 45/99] fbdev/matroxfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/matrox/matroxfb_base.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/matrox/matroxfb_base.c b/drivers/video/fbdev/matrox/matroxfb_base.c
index a043a737ea9f..f690ee0c9b1f 100644
--- a/drivers/video/fbdev/matrox/matroxfb_base.c
+++ b/drivers/video/fbdev/matrox/matroxfb_base.c
@@ -101,6 +101,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/version.h>
 
 #include "matroxfb_base.h"
@@ -2333,17 +2334,14 @@ static void __exit matrox_done(void) {
 
 /* ************************* init in-kernel code ************************** */
 
-static int __init matroxfb_setup(char *options) {
-	char *this_opt;
-
-	DBG(__func__)
-
-	if (!options || !*options)
-		return 0;
+static int __init matroxfb_setup(const char *options)
+{
+	struct option_iter iter;
+	const char *this_opt;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		dprintk("matroxfb_setup: option %s\n", this_opt);
 
 		if (!strncmp(this_opt, "dev:", 4))
@@ -2467,6 +2465,9 @@ static int __init matroxfb_setup(char *options) {
 			}
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 45/99] fbdev/matroxfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/matrox/matroxfb_base.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/matrox/matroxfb_base.c b/drivers/video/fbdev/matrox/matroxfb_base.c
index a043a737ea9f..f690ee0c9b1f 100644
--- a/drivers/video/fbdev/matrox/matroxfb_base.c
+++ b/drivers/video/fbdev/matrox/matroxfb_base.c
@@ -101,6 +101,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/version.h>
 
 #include "matroxfb_base.h"
@@ -2333,17 +2334,14 @@ static void __exit matrox_done(void) {
 
 /* ************************* init in-kernel code ************************** */
 
-static int __init matroxfb_setup(char *options) {
-	char *this_opt;
-
-	DBG(__func__)
-
-	if (!options || !*options)
-		return 0;
+static int __init matroxfb_setup(const char *options)
+{
+	struct option_iter iter;
+	const char *this_opt;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		dprintk("matroxfb_setup: option %s\n", this_opt);
 
 		if (!strncmp(this_opt, "dev:", 4))
@@ -2467,6 +2465,9 @@ static int __init matroxfb_setup(char *options) {
 			}
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 46/99] fbdev/mx3fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/mx3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index 76771e126d0a..cf14fe08567a 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -1666,8 +1666,17 @@ static int __init mx3fb_setup(void)
 			continue;
 		if (!strncmp(opt, "bpp=", 4))
 			default_bpp = simple_strtoul(opt + 4, NULL, 0);
-		else
-			fb_mode = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "mx3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "mx3fb: option too long\n"))
+				continue;
+			fb_mode = mode_option_buf;
+		}
 	}
 #endif
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 46/99] fbdev/mx3fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/mx3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index 76771e126d0a..cf14fe08567a 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -1666,8 +1666,17 @@ static int __init mx3fb_setup(void)
 			continue;
 		if (!strncmp(opt, "bpp=", 4))
 			default_bpp = simple_strtoul(opt + 4, NULL, 0);
-		else
-			fb_mode = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "mx3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "mx3fb: option too long\n"))
+				continue;
+			fb_mode = mode_option_buf;
+		}
 	}
 #endif
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 47/99] fbdev/mx3fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/mx3fb.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index cf14fe08567a..cb9f5ac69e79 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -6,6 +6,7 @@
  * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
@@ -1653,17 +1654,16 @@ static struct platform_driver mx3fb_driver = {
 static int __init mx3fb_setup(void)
 {
 #ifndef MODULE
-	char *opt, *options = NULL;
+	char *options = NULL;
+	struct option_iter iter;
+	const char *opt;
 
 	if (fb_get_options("mx3fb", &options))
 		return -ENODEV;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	while (option_iter_next(&iter, opt)) {
 		if (!strncmp(opt, "bpp=", 4))
 			default_bpp = simple_strtoul(opt + 4, NULL, 0);
 		else {
@@ -1678,6 +1678,8 @@ static int __init mx3fb_setup(void)
 			fb_mode = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
 #endif
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 47/99] fbdev/mx3fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/mx3fb.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index cf14fe08567a..cb9f5ac69e79 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -6,6 +6,7 @@
  * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
@@ -1653,17 +1654,16 @@ static struct platform_driver mx3fb_driver = {
 static int __init mx3fb_setup(void)
 {
 #ifndef MODULE
-	char *opt, *options = NULL;
+	char *options = NULL;
+	struct option_iter iter;
+	const char *opt;
 
 	if (fb_get_options("mx3fb", &options))
 		return -ENODEV;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	while (option_iter_next(&iter, opt)) {
 		if (!strncmp(opt, "bpp=", 4))
 			default_bpp = simple_strtoul(opt + 4, NULL, 0);
 		else {
@@ -1678,6 +1678,8 @@ static int __init mx3fb_setup(void)
 			fb_mode = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
 #endif
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 48/99] fbdev/neofb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/neofb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c
index 39d8cdef5c97..958111f7d63c 100644
--- a/drivers/video/fbdev/neofb.c
+++ b/drivers/video/fbdev/neofb.c
@@ -2198,8 +2198,17 @@ static int __init neofb_setup(char *options)
 			nopciburst = 1;
 		else if (!strncmp(this_opt, "libretto", 8))
 			libretto = 1;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "neofb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "neofb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 48/99] fbdev/neofb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/neofb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c
index 39d8cdef5c97..958111f7d63c 100644
--- a/drivers/video/fbdev/neofb.c
+++ b/drivers/video/fbdev/neofb.c
@@ -2198,8 +2198,17 @@ static int __init neofb_setup(char *options)
 			nopciburst = 1;
 		else if (!strncmp(this_opt, "libretto", 8))
 			libretto = 1;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "neofb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "neofb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 49/99] fbdev/neofb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/neofb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c
index 958111f7d63c..e9b132d660ab 100644
--- a/drivers/video/fbdev/neofb.c
+++ b/drivers/video/fbdev/neofb.c
@@ -55,6 +55,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2175,19 +2176,16 @@ static struct pci_driver neofb_driver = {
 /* ************************* init in-kernel code ************************** */
 
 #ifndef MODULE
-static int __init neofb_setup(char *options)
+static int __init neofb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	DBG("neofb_setup");
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "internal", 8))
 			internal = 1;
 		else if (!strncmp(this_opt, "external", 8))
@@ -2210,6 +2208,9 @@ static int __init neofb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 49/99] fbdev/neofb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/neofb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c
index 958111f7d63c..e9b132d660ab 100644
--- a/drivers/video/fbdev/neofb.c
+++ b/drivers/video/fbdev/neofb.c
@@ -55,6 +55,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2175,19 +2176,16 @@ static struct pci_driver neofb_driver = {
 /* ************************* init in-kernel code ************************** */
 
 #ifndef MODULE
-static int __init neofb_setup(char *options)
+static int __init neofb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	DBG("neofb_setup");
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "internal", 8))
 			internal = 1;
 		else if (!strncmp(this_opt, "external", 8))
@@ -2210,6 +2208,9 @@ static int __init neofb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 50/99] fbdev/nvidiafb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/nvidia/nvidia.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index e60a276b4855..eb91201babd4 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -1498,8 +1498,17 @@ static int nvidiafb_setup(char *options)
 			fpdither = simple_strtol(this_opt+9, NULL, 0);
 		} else if (!strncmp(this_opt, "bpp:", 4)) {
 			bpp = simple_strtoul(this_opt+4, NULL, 0);
-		} else
-			mode_option = this_opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "nvidiafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "nvidiafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	NVTRACE_LEAVE();
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 50/99] fbdev/nvidiafb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/nvidia/nvidia.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index e60a276b4855..eb91201babd4 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -1498,8 +1498,17 @@ static int nvidiafb_setup(char *options)
 			fpdither = simple_strtol(this_opt+9, NULL, 0);
 		} else if (!strncmp(this_opt, "bpp:", 4)) {
 			bpp = simple_strtoul(this_opt+4, NULL, 0);
-		} else
-			mode_option = this_opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "nvidiafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "nvidiafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	NVTRACE_LEAVE();
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 51/99] fbdev/nvidiafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/nvidia/nvidia.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index eb91201babd4..58b1b13f09dd 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1458,17 +1459,18 @@ static void nvidiafb_remove(struct pci_dev *pd)
  * ------------------------------------------------------------------------- */
 
 #ifndef MODULE
-static int nvidiafb_setup(char *options)
+static int nvidiafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	NVTRACE_ENTER();
-	if (!options || !*options)
-		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "forceCRTC", 9)) {
-			char *p;
+			const char *p;
 
 			p = this_opt + 9;
 			if (!*p || !*(++p))
@@ -1510,6 +1512,9 @@ static int nvidiafb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	NVTRACE_LEAVE();
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 51/99] fbdev/nvidiafb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/nvidia/nvidia.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index eb91201babd4..58b1b13f09dd 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1458,17 +1459,18 @@ static void nvidiafb_remove(struct pci_dev *pd)
  * ------------------------------------------------------------------------- */
 
 #ifndef MODULE
-static int nvidiafb_setup(char *options)
+static int nvidiafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	NVTRACE_ENTER();
-	if (!options || !*options)
-		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "forceCRTC", 9)) {
-			char *p;
+			const char *p;
 
 			p = this_opt + 9;
 			if (!*p || !*(++p))
@@ -1510,6 +1512,9 @@ static int nvidiafb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	NVTRACE_LEAVE();
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 52/99] fbdev/ocfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ocfb.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c
index da7e1457e58f..34684191f2f0 100644
--- a/drivers/video/fbdev/ocfb.c
+++ b/drivers/video/fbdev/ocfb.c
@@ -75,9 +75,18 @@ static int __init ocfb_setup(char *options)
 		return 0;
 
 	while ((curr_opt = strsep(&options, ",")) != NULL) {
+		static char mode_option_buf[256];
+		int ret;
+
 		if (!*curr_opt)
 			continue;
-		mode_option = curr_opt;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", curr_opt);
+		if (WARN(ret < 0, "ocfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "ocfb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 52/99] fbdev/ocfb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ocfb.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c
index da7e1457e58f..34684191f2f0 100644
--- a/drivers/video/fbdev/ocfb.c
+++ b/drivers/video/fbdev/ocfb.c
@@ -75,9 +75,18 @@ static int __init ocfb_setup(char *options)
 		return 0;
 
 	while ((curr_opt = strsep(&options, ",")) != NULL) {
+		static char mode_option_buf[256];
+		int ret;
+
 		if (!*curr_opt)
 			continue;
-		mode_option = curr_opt;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", curr_opt);
+		if (WARN(ret < 0, "ocfb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "ocfb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 53/99] fbdev/ocfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ocfb.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c
index 34684191f2f0..546230483f53 100644
--- a/drivers/video/fbdev/ocfb.c
+++ b/drivers/video/fbdev/ocfb.c
@@ -8,6 +8,7 @@
  * kind, whether express or implied.
  */
 
+#include <linux/cmdline.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/errno.h>
@@ -67,20 +68,17 @@ struct ocfb_dev {
 };
 
 #ifndef MODULE
-static int __init ocfb_setup(char *options)
+static int __init ocfb_setup(const char *options)
 {
-	char *curr_opt;
+	struct option_iter iter;
+	const char *curr_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((curr_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, curr_opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
-		if (!*curr_opt)
-			continue;
-
 		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", curr_opt);
 		if (WARN(ret < 0, "ocfb: ignoring invalid option, ret=%d\n", ret))
 			continue;
@@ -89,6 +87,8 @@ static int __init ocfb_setup(char *options)
 		mode_option = mode_option_buf;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 53/99] fbdev/ocfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ocfb.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c
index 34684191f2f0..546230483f53 100644
--- a/drivers/video/fbdev/ocfb.c
+++ b/drivers/video/fbdev/ocfb.c
@@ -8,6 +8,7 @@
  * kind, whether express or implied.
  */
 
+#include <linux/cmdline.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/errno.h>
@@ -67,20 +68,17 @@ struct ocfb_dev {
 };
 
 #ifndef MODULE
-static int __init ocfb_setup(char *options)
+static int __init ocfb_setup(const char *options)
 {
-	char *curr_opt;
+	struct option_iter iter;
+	const char *curr_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((curr_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, curr_opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
-		if (!*curr_opt)
-			continue;
-
 		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", curr_opt);
 		if (WARN(ret < 0, "ocfb: ignoring invalid option, ret=%d\n", ret))
 			continue;
@@ -89,6 +87,8 @@ static int __init ocfb_setup(char *options)
 		mode_option = mode_option_buf;
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 54/99] fbdev/omapfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/omap/omapfb_main.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index 1f3df2055ff0..464a667708db 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -11,6 +11,7 @@
  *   Dirk Behme <dirk.behme@de.bosch.com>  - changes for 2.6 kernel API
  *   Texas Instruments                     - H3 support
  */
+#include <linux/cmdline.h>
 #include <linux/platform_device.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
@@ -1842,17 +1843,17 @@ static struct platform_driver omapfb_driver = {
 #ifndef MODULE
 
 /* Process kernel command line parameters */
-static int __init omapfb_setup(char *options)
+static int __init omapfb_setup(const char *options)
 {
-	char *this_opt = NULL;
+	struct option_iter iter;
+	const char *this_opt;
 	int r = 0;
 
 	pr_debug("omapfb: options %s\n", options);
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while (!r && (this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "accel", 5))
 			def_accel = 1;
 		else if (!strncmp(this_opt, "vram:", 5)) {
@@ -1893,6 +1894,8 @@ static int __init omapfb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return r;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 54/99] fbdev/omapfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/omap/omapfb_main.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index 1f3df2055ff0..464a667708db 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -11,6 +11,7 @@
  *   Dirk Behme <dirk.behme@de.bosch.com>  - changes for 2.6 kernel API
  *   Texas Instruments                     - H3 support
  */
+#include <linux/cmdline.h>
 #include <linux/platform_device.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
@@ -1842,17 +1843,17 @@ static struct platform_driver omapfb_driver = {
 #ifndef MODULE
 
 /* Process kernel command line parameters */
-static int __init omapfb_setup(char *options)
+static int __init omapfb_setup(const char *options)
 {
-	char *this_opt = NULL;
+	struct option_iter iter;
+	const char *this_opt;
 	int r = 0;
 
 	pr_debug("omapfb: options %s\n", options);
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while (!r && (this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "accel", 5))
 			def_accel = 1;
 		else if (!strncmp(this_opt, "vram:", 5)) {
@@ -1893,6 +1894,8 @@ static int __init omapfb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return r;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 55/99] fbdev/platinumfb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/platinumfb.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index 5b9e26ea6449..c7172174c1b7 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -52,17 +52,17 @@ struct fb_info_platinum {
 		__u8 red, green, blue;
 	}				palette[256];
 	u32				pseudo_palette[16];
-	
+
 	volatile struct cmap_regs	__iomem *cmap_regs;
 	unsigned long			cmap_regs_phys;
-	
+
 	volatile struct platinum_regs	__iomem *platinum_regs;
 	unsigned long			platinum_regs_phys;
-	
+
 	__u8				__iomem *frame_buffer;
 	volatile __u8			__iomem *base_frame_buffer;
 	unsigned long			frame_buffer_phys;
-	
+
 	unsigned long			total_vram;
 	int				clktype;
 	int				dactype;
@@ -133,7 +133,7 @@ static int platinumfb_set_par (struct fb_info *info)
 	platinum_set_hardware(pinfo);
 
 	init = platinum_reg_init[pinfo->vmode-1];
-	
+
  	if ((pinfo->vmode == VMODE_832_624_75) && (pinfo->cmode > CMODE_8))
   		offset = 0x10;
 
@@ -214,7 +214,7 @@ static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 			break;
 		}
 	}
-	
+
 	return 0;
 }
 
@@ -269,7 +269,7 @@ static void platinum_set_hardware(struct fb_info_platinum *pinfo)
 	struct platinum_regvals		*init;
 	int				i;
 	int				vmode, cmode;
-	
+
 	vmode = pinfo->vmode;
 	cmode = pinfo->cmode;
 
@@ -436,7 +436,7 @@ static int read_platinum_sense(struct fb_info_platinum *info)
  * This routine takes a user-supplied var, and picks the best vmode/cmode from it.
  * It also updates the var structure to the actual mode data obtained
  */
-static int platinum_var_to_par(struct fb_var_screeninfo *var, 
+static int platinum_var_to_par(struct fb_var_screeninfo *var,
 			       struct fb_info_platinum *pinfo,
 			       int check_only)
 {
@@ -478,12 +478,12 @@ static int platinum_var_to_par(struct fb_var_screeninfo *var,
 	pinfo->yoffset = 0;
 	pinfo->vxres = pinfo->xres;
 	pinfo->vyres = pinfo->yres;
-	
+
 	return 0;
 }
 
 
-/* 
+/*
  * Parse user specified options (`video=platinumfb:')
  */
 static int __init platinumfb_setup(char *options)
@@ -624,7 +624,7 @@ static int platinumfb_probe(struct platform_device* odev)
 		break;
 	}
 	dev_set_drvdata(&odev->dev, info);
-	
+
 	rc = platinum_init_fb(info);
 	if (rc != 0) {
 		iounmap(pinfo->frame_buffer);
@@ -640,9 +640,9 @@ static int platinumfb_remove(struct platform_device* odev)
 {
 	struct fb_info		*info = dev_get_drvdata(&odev->dev);
 	struct fb_info_platinum	*pinfo = info->par;
-	
+
         unregister_framebuffer (info);
-	
+
 	/* Unmap frame buffer and registers */
 	iounmap(pinfo->frame_buffer);
 	iounmap(pinfo->platinum_regs);
@@ -658,7 +658,7 @@ static int platinumfb_remove(struct platform_device* odev)
 	return 0;
 }
 
-static struct of_device_id platinumfb_match[] = 
+static struct of_device_id platinumfb_match[] =
 {
 	{
 	.name 		= "platinum",
@@ -666,7 +666,7 @@ static struct of_device_id platinumfb_match[] =
 	{},
 };
 
-static struct platform_driver platinum_driver = 
+static struct platform_driver platinum_driver =
 {
 	.driver = {
 		.name = "platinumfb",
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 55/99] fbdev/platinumfb: Remove trailing whitespaces
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/platinumfb.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index 5b9e26ea6449..c7172174c1b7 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -52,17 +52,17 @@ struct fb_info_platinum {
 		__u8 red, green, blue;
 	}				palette[256];
 	u32				pseudo_palette[16];
-	
+
 	volatile struct cmap_regs	__iomem *cmap_regs;
 	unsigned long			cmap_regs_phys;
-	
+
 	volatile struct platinum_regs	__iomem *platinum_regs;
 	unsigned long			platinum_regs_phys;
-	
+
 	__u8				__iomem *frame_buffer;
 	volatile __u8			__iomem *base_frame_buffer;
 	unsigned long			frame_buffer_phys;
-	
+
 	unsigned long			total_vram;
 	int				clktype;
 	int				dactype;
@@ -133,7 +133,7 @@ static int platinumfb_set_par (struct fb_info *info)
 	platinum_set_hardware(pinfo);
 
 	init = platinum_reg_init[pinfo->vmode-1];
-	
+
  	if ((pinfo->vmode == VMODE_832_624_75) && (pinfo->cmode > CMODE_8))
   		offset = 0x10;
 
@@ -214,7 +214,7 @@ static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 			break;
 		}
 	}
-	
+
 	return 0;
 }
 
@@ -269,7 +269,7 @@ static void platinum_set_hardware(struct fb_info_platinum *pinfo)
 	struct platinum_regvals		*init;
 	int				i;
 	int				vmode, cmode;
-	
+
 	vmode = pinfo->vmode;
 	cmode = pinfo->cmode;
 
@@ -436,7 +436,7 @@ static int read_platinum_sense(struct fb_info_platinum *info)
  * This routine takes a user-supplied var, and picks the best vmode/cmode from it.
  * It also updates the var structure to the actual mode data obtained
  */
-static int platinum_var_to_par(struct fb_var_screeninfo *var, 
+static int platinum_var_to_par(struct fb_var_screeninfo *var,
 			       struct fb_info_platinum *pinfo,
 			       int check_only)
 {
@@ -478,12 +478,12 @@ static int platinum_var_to_par(struct fb_var_screeninfo *var,
 	pinfo->yoffset = 0;
 	pinfo->vxres = pinfo->xres;
 	pinfo->vyres = pinfo->yres;
-	
+
 	return 0;
 }
 
 
-/* 
+/*
  * Parse user specified options (`video=platinumfb:')
  */
 static int __init platinumfb_setup(char *options)
@@ -624,7 +624,7 @@ static int platinumfb_probe(struct platform_device* odev)
 		break;
 	}
 	dev_set_drvdata(&odev->dev, info);
-	
+
 	rc = platinum_init_fb(info);
 	if (rc != 0) {
 		iounmap(pinfo->frame_buffer);
@@ -640,9 +640,9 @@ static int platinumfb_remove(struct platform_device* odev)
 {
 	struct fb_info		*info = dev_get_drvdata(&odev->dev);
 	struct fb_info_platinum	*pinfo = info->par;
-	
+
         unregister_framebuffer (info);
-	
+
 	/* Unmap frame buffer and registers */
 	iounmap(pinfo->frame_buffer);
 	iounmap(pinfo->platinum_regs);
@@ -658,7 +658,7 @@ static int platinumfb_remove(struct platform_device* odev)
 	return 0;
 }
 
-static struct of_device_id platinumfb_match[] = 
+static struct of_device_id platinumfb_match[] =
 {
 	{
 	.name 		= "platinum",
@@ -666,7 +666,7 @@ static struct of_device_id platinumfb_match[] =
 	{},
 };
 
-static struct platform_driver platinum_driver = 
+static struct platform_driver platinum_driver =
 {
 	.driver = {
 		.name = "platinumfb",
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 56/99] fbdev/platinumfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/platinumfb.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index c7172174c1b7..71d5b7c169e7 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -19,6 +19,7 @@
 
 #undef DEBUG
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -486,14 +487,14 @@ static int platinum_var_to_par(struct fb_var_screeninfo *var,
 /*
  * Parse user specified options (`video=platinumfb:')
  */
-static int __init platinumfb_setup(char *options)
+static int __init platinumfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "vmode:", 6)) {
 	    		int vmode = simple_strtoul(this_opt+6, NULL, 0);
 			if (vmode > 0 && vmode <= VMODE_MAX)
@@ -516,6 +517,9 @@ static int __init platinumfb_setup(char *options)
 			}
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 56/99] fbdev/platinumfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/platinumfb.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index c7172174c1b7..71d5b7c169e7 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -19,6 +19,7 @@
 
 #undef DEBUG
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -486,14 +487,14 @@ static int platinum_var_to_par(struct fb_var_screeninfo *var,
 /*
  * Parse user specified options (`video=platinumfb:')
  */
-static int __init platinumfb_setup(char *options)
+static int __init platinumfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "vmode:", 6)) {
 	    		int vmode = simple_strtoul(this_opt+6, NULL, 0);
 			if (vmode > 0 && vmode <= VMODE_MAX)
@@ -516,6 +517,9 @@ static int __init platinumfb_setup(char *options)
 			}
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 57/99] fbdev/pm2fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm2fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index 47d212944f30..c6a117538fd8 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -1792,8 +1792,17 @@ static int __init pm2fb_setup(char *options)
 			nomtrr = 1;
 		else if (!strncmp(this_opt, "noaccel", 7))
 			noaccel = 1;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "pm2fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "pm2fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 57/99] fbdev/pm2fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm2fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index 47d212944f30..c6a117538fd8 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -1792,8 +1792,17 @@ static int __init pm2fb_setup(char *options)
 			nomtrr = 1;
 		else if (!strncmp(this_opt, "noaccel", 7))
 			noaccel = 1;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "pm2fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "pm2fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 58/99] fbdev/pm2fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm2fb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index c6a117538fd8..a6a793efb0fe 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -28,6 +28,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -1772,16 +1773,14 @@ MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
  *
  * This is, comma-separated options following `video=pm2fb:'.
  */
-static int __init pm2fb_setup(char *options)
+static int __init pm2fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "lowhsync"))
 			lowhsync = 1;
 		else if (!strcmp(this_opt, "lowvsync"))
@@ -1804,6 +1803,9 @@ static int __init pm2fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 58/99] fbdev/pm2fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm2fb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index c6a117538fd8..a6a793efb0fe 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -28,6 +28,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -1772,16 +1773,14 @@ MODULE_DEVICE_TABLE(pci, pm2fb_id_table);
  *
  * This is, comma-separated options following `video=pm2fb:'.
  */
-static int __init pm2fb_setup(char *options)
+static int __init pm2fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "lowhsync"))
 			lowhsync = 1;
 		else if (!strcmp(this_opt, "lowvsync"))
@@ -1804,6 +1803,9 @@ static int __init pm2fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 59/99] fbdev/pm3fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index b46a471df9ae..d0a2cf623c60 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -1526,8 +1526,17 @@ static int __init pm3fb_setup(char *options)
 			hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
 		else if (!strncmp(this_opt, "nomtrr", 6))
 			nomtrr = 1;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "pm3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "pm3fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 59/99] fbdev/pm3fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index b46a471df9ae..d0a2cf623c60 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -1526,8 +1526,17 @@ static int __init pm3fb_setup(char *options)
 			hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
 		else if (!strncmp(this_opt, "nomtrr", 6))
 			nomtrr = 1;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "pm3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "pm3fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 60/99] fbdev/pm3fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm3fb.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index d0a2cf623c60..4eec0ad1e984 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -23,6 +23,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1509,18 +1510,16 @@ MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
  * Only necessary if your driver takes special options,
  * otherwise we fall back on the generic fb_setup().
  */
-static int __init pm3fb_setup(char *options)
+static int __init pm3fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	/* Parse user specified options (`video=pm3fb:') */
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
-		else if (!strncmp(this_opt, "noaccel", 7))
+	while (option_iter_next(&iter, this_opt)) {
+		if (!strncmp(this_opt, "noaccel", 7))
 			noaccel = 1;
 		else if (!strncmp(this_opt, "hwcursor=", 9))
 			hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
@@ -1538,6 +1537,9 @@ static int __init pm3fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif /* MODULE */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 60/99] fbdev/pm3fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pm3fb.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index d0a2cf623c60..4eec0ad1e984 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -23,6 +23,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1509,18 +1510,16 @@ MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
  * Only necessary if your driver takes special options,
  * otherwise we fall back on the generic fb_setup().
  */
-static int __init pm3fb_setup(char *options)
+static int __init pm3fb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	/* Parse user specified options (`video=pm3fb:') */
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
-		else if (!strncmp(this_opt, "noaccel", 7))
+	while (option_iter_next(&iter, this_opt)) {
+		if (!strncmp(this_opt, "noaccel", 7))
 			noaccel = 1;
 		else if (!strncmp(this_opt, "hwcursor=", 9))
 			hwcursor = simple_strtoul(this_opt + 9, NULL, 0);
@@ -1538,6 +1537,9 @@ static int __init pm3fb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif /* MODULE */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 61/99] fbdev/ps3fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ps3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index 2fe08b67eda7..87543411acaf 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -1276,8 +1276,17 @@ static int __init ps3fb_setup(void)
 			continue;
 		if (!strncmp(this_opt, "mode:", 5))
 			ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "ps3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "ps3fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 61/99] fbdev/ps3fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ps3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index 2fe08b67eda7..87543411acaf 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -1276,8 +1276,17 @@ static int __init ps3fb_setup(void)
 			continue;
 		if (!strncmp(this_opt, "mode:", 5))
 			ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "ps3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "ps3fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 62/99] fbdev/ps3fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ps3fb.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index 87543411acaf..d7c287089c64 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -17,6 +17,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1256,6 +1257,8 @@ static struct ps3_system_bus_driver ps3fb_driver = {
 static int __init ps3fb_setup(void)
 {
 	char *options;
+	struct option_iter iter;
+	const char *this_opt;
 
 #ifdef MODULE
 	return 0;
@@ -1264,16 +1267,9 @@ static int __init ps3fb_setup(void)
 	if (fb_get_options(DEVICE_NAME, &options))
 		return -ENXIO;
 
-	if (!options || !*options)
-		return 0;
-
-	while (1) {
-		char *this_opt = strsep(&options, ",");
+	option_iter_init(&iter, options);
 
-		if (!this_opt)
-			break;
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "mode:", 5))
 			ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
 		else {
@@ -1288,6 +1284,9 @@ static int __init ps3fb_setup(void)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 62/99] fbdev/ps3fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/ps3fb.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index 87543411acaf..d7c287089c64 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -17,6 +17,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1256,6 +1257,8 @@ static struct ps3_system_bus_driver ps3fb_driver = {
 static int __init ps3fb_setup(void)
 {
 	char *options;
+	struct option_iter iter;
+	const char *this_opt;
 
 #ifdef MODULE
 	return 0;
@@ -1264,16 +1267,9 @@ static int __init ps3fb_setup(void)
 	if (fb_get_options(DEVICE_NAME, &options))
 		return -ENXIO;
 
-	if (!options || !*options)
-		return 0;
-
-	while (1) {
-		char *this_opt = strsep(&options, ",");
+	option_iter_init(&iter, options);
 
-		if (!this_opt)
-			break;
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "mode:", 5))
 			ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
 		else {
@@ -1288,6 +1284,9 @@ static int __init ps3fb_setup(void)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 63/99] fbdev/pvr2fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pvr2fb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index 6888127a5eb8..cd778f8753f1 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -1049,7 +1049,15 @@ static int __init pvr2fb_setup(char *options)
 		} else if (!strncmp(this_opt, "nowrap", 6)) {
 			nowrap = 1;
 		} else {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "pvr2fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "pvr2fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		}
 	}
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 63/99] fbdev/pvr2fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pvr2fb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index 6888127a5eb8..cd778f8753f1 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -1049,7 +1049,15 @@ static int __init pvr2fb_setup(char *options)
 		} else if (!strncmp(this_opt, "nowrap", 6)) {
 			nowrap = 1;
 		} else {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "pvr2fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "pvr2fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		}
 	}
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 64/99] fbdev/pvr2fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pvr2fb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index cd778f8753f1..9255b3506b81 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -46,6 +46,7 @@
 #undef DEBUG
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1024,20 +1025,18 @@ static void pvr2fb_pci_exit(void)
  */
 
 #ifndef MODULE
-static int __init pvr2fb_setup(char *options)
+static int __init pvr2fb_setup(const char *options)
 {
-	char *this_opt;
 	char cable_arg[80];
 	char output_arg[80];
-
-	if (!options || !*options)
-		return 0;
+	struct option_iter iter;
+	const char *this_opt;
 
 	cable_arg[0] = output_arg[0] = 0;
 
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "inverse")) {
 			fb_invert_cmaps();
 		} else if (!strncmp(this_opt, "cable:", 6)) {
@@ -1061,6 +1060,8 @@ static int __init pvr2fb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	if (*cable_arg)
 		cable_type = pvr2_get_param_val(cables, cable_arg, 3);
 	if (*output_arg)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 64/99] fbdev/pvr2fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pvr2fb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index cd778f8753f1..9255b3506b81 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -46,6 +46,7 @@
 #undef DEBUG
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1024,20 +1025,18 @@ static void pvr2fb_pci_exit(void)
  */
 
 #ifndef MODULE
-static int __init pvr2fb_setup(char *options)
+static int __init pvr2fb_setup(const char *options)
 {
-	char *this_opt;
 	char cable_arg[80];
 	char output_arg[80];
-
-	if (!options || !*options)
-		return 0;
+	struct option_iter iter;
+	const char *this_opt;
 
 	cable_arg[0] = output_arg[0] = 0;
 
-	while ((this_opt = strsep(&options, ","))) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "inverse")) {
 			fb_invert_cmaps();
 		} else if (!strncmp(this_opt, "cable:", 6)) {
@@ -1061,6 +1060,8 @@ static int __init pvr2fb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	if (*cable_arg)
 		cable_type = pvr2_get_param_val(cables, cable_arg, 3);
 	if (*output_arg)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 65/99] fbdev/pxafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pxafb.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index c46ed78298ae..1937a58e47a1 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -32,6 +32,7 @@
  *   All Rights Reserved
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -2011,23 +2012,26 @@ static int parse_opt(struct device *dev, char *this_opt,
 	return 0;
 }
 
-static int pxafb_parse_options(struct device *dev, char *options,
+static int pxafb_parse_options(struct device *dev, const char *options,
 			       struct pxafb_mach_info *inf)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 	int ret;
 
-	if (!options || !*options)
-		return 0;
-
 	dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
 
-	/* could be made table driven or similar?... */
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
+		/* could be made table driven or similar?... */
 		ret = parse_opt(dev, this_opt, inf);
 		if (ret)
 			return ret;
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 65/99] fbdev/pxafb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/pxafb.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index c46ed78298ae..1937a58e47a1 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -32,6 +32,7 @@
  *   All Rights Reserved
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -2011,23 +2012,26 @@ static int parse_opt(struct device *dev, char *this_opt,
 	return 0;
 }
 
-static int pxafb_parse_options(struct device *dev, char *options,
+static int pxafb_parse_options(struct device *dev, const char *options,
 			       struct pxafb_mach_info *inf)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 	int ret;
 
-	if (!options || !*options)
-		return 0;
-
 	dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
 
-	/* could be made table driven or similar?... */
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
+		/* could be made table driven or similar?... */
 		ret = parse_opt(dev, this_opt, inf);
 		if (ret)
 			return ret;
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 66/99] fbdev/rivafb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/riva/fbdev.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c
index 41edc6e79460..affb7c5ef69c 100644
--- a/drivers/video/fbdev/riva/fbdev.c
+++ b/drivers/video/fbdev/riva/fbdev.c
@@ -2132,8 +2132,17 @@ static int rivafb_setup(char *options)
 			strictmode = 1;
 		} else if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = 1;
-		} else
-			mode_option = this_opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "rivafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "rivafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	NVTRACE_LEAVE();
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 66/99] fbdev/rivafb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/riva/fbdev.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c
index 41edc6e79460..affb7c5ef69c 100644
--- a/drivers/video/fbdev/riva/fbdev.c
+++ b/drivers/video/fbdev/riva/fbdev.c
@@ -2132,8 +2132,17 @@ static int rivafb_setup(char *options)
 			strictmode = 1;
 		} else if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = 1;
-		} else
-			mode_option = this_opt;
+		} else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "rivafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "rivafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	NVTRACE_LEAVE();
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 67/99] fbdev/rivafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/riva/fbdev.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c
index affb7c5ef69c..d95319bb93cc 100644
--- a/drivers/video/fbdev/riva/fbdev.c
+++ b/drivers/video/fbdev/riva/fbdev.c
@@ -30,6 +30,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2105,17 +2106,18 @@ static void rivafb_remove(struct pci_dev *pd)
  * ------------------------------------------------------------------------- */
 
 #ifndef MODULE
-static int rivafb_setup(char *options)
+static int rivafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	NVTRACE_ENTER();
-	if (!options || !*options)
-		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "forceCRTC", 9)) {
-			char *p;
+			const char *p;
 
 			p = this_opt + 9;
 			if (!*p || !*(++p)) continue;
@@ -2144,6 +2146,9 @@ static int rivafb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	NVTRACE_LEAVE();
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 67/99] fbdev/rivafb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/riva/fbdev.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c
index affb7c5ef69c..d95319bb93cc 100644
--- a/drivers/video/fbdev/riva/fbdev.c
+++ b/drivers/video/fbdev/riva/fbdev.c
@@ -30,6 +30,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2105,17 +2106,18 @@ static void rivafb_remove(struct pci_dev *pd)
  * ------------------------------------------------------------------------- */
 
 #ifndef MODULE
-static int rivafb_setup(char *options)
+static int rivafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	NVTRACE_ENTER();
-	if (!options || !*options)
-		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "forceCRTC", 9)) {
-			char *p;
+			const char *p;
 
 			p = this_opt + 9;
 			if (!*p || !*(++p)) continue;
@@ -2144,6 +2146,9 @@ static int rivafb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	NVTRACE_LEAVE();
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 68/99] fbdev/s3fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/s3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index 7d257489edcc..70aefd7224a1 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -1535,8 +1535,17 @@ static int  __init s3fb_setup(char *options)
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
 		else if (!strncmp(opt, "fasttext:", 9))
 			fasttext = simple_strtoul(opt + 9, NULL, 0);
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "s3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "s3fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 68/99] fbdev/s3fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/s3fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index 7d257489edcc..70aefd7224a1 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -1535,8 +1535,17 @@ static int  __init s3fb_setup(char *options)
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
 		else if (!strncmp(opt, "fasttext:", 9))
 			fasttext = simple_strtoul(opt + 9, NULL, 0);
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "s3fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "s3fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 69/99] fbdev/s3fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/s3fb.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index 70aefd7224a1..f3bd7b1c2c9a 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1520,18 +1521,15 @@ static struct pci_driver s3fb_pci_driver = {
 /* Parse user specified options */
 
 #ifndef MODULE
-static int  __init s3fb_setup(char *options)
+static int  __init s3fb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
 
-		if (!*opt)
-			continue;
-		else if (!strncmp(opt, "mtrr:", 5))
+	while (option_iter_next(&iter, opt)) {
+		if (!strncmp(opt, "mtrr:", 5))
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
 		else if (!strncmp(opt, "fasttext:", 9))
 			fasttext = simple_strtoul(opt + 9, NULL, 0);
@@ -1548,6 +1546,8 @@ static int  __init s3fb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 69/99] fbdev/s3fb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/s3fb.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index 70aefd7224a1..f3bd7b1c2c9a 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1520,18 +1521,15 @@ static struct pci_driver s3fb_pci_driver = {
 /* Parse user specified options */
 
 #ifndef MODULE
-static int  __init s3fb_setup(char *options)
+static int  __init s3fb_setup(const char *options)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((opt = strsep(&options, ",")) != NULL) {
+	option_iter_init(&iter, options);
 
-		if (!*opt)
-			continue;
-		else if (!strncmp(opt, "mtrr:", 5))
+	while (option_iter_next(&iter, opt)) {
+		if (!strncmp(opt, "mtrr:", 5))
 			mtrr = simple_strtoul(opt + 5, NULL, 0);
 		else if (!strncmp(opt, "fasttext:", 9))
 			fasttext = simple_strtoul(opt + 9, NULL, 0);
@@ -1548,6 +1546,8 @@ static int  __init s3fb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 70/99] fbdev/savagefb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/savage/savagefb_driver.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c
index 4a27b68798bf..19fffe0b6cdd 100644
--- a/drivers/video/fbdev/savage/savagefb_driver.c
+++ b/drivers/video/fbdev/savage/savagefb_driver.c
@@ -2544,7 +2544,15 @@ static int __init savagefb_setup(char *options)
 		return 0;
 
 	while ((this_opt = strsep(&options, ",")) != NULL) {
-		mode_option = this_opt;
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+		if (WARN(ret < 0, "savagefb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "savagefb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
 	}
 #endif /* !MODULE */
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 70/99] fbdev/savagefb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/savage/savagefb_driver.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c
index 4a27b68798bf..19fffe0b6cdd 100644
--- a/drivers/video/fbdev/savage/savagefb_driver.c
+++ b/drivers/video/fbdev/savage/savagefb_driver.c
@@ -2544,7 +2544,15 @@ static int __init savagefb_setup(char *options)
 		return 0;
 
 	while ((this_opt = strsep(&options, ",")) != NULL) {
-		mode_option = this_opt;
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+		if (WARN(ret < 0, "savagefb: ignoring invalid option, ret=%d\n", ret))
+			continue;
+		if (WARN(ret >= sizeof(mode_option_buf), "savagefb: option too long\n"))
+			continue;
+		mode_option = mode_option_buf;
 	}
 #endif /* !MODULE */
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 71/99] fbdev/savagefb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/savage/savagefb_driver.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c
index 19fffe0b6cdd..94026848d67d 100644
--- a/drivers/video/fbdev/savage/savagefb_driver.c
+++ b/drivers/video/fbdev/savage/savagefb_driver.c
@@ -42,6 +42,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2535,15 +2536,15 @@ static void __exit savage_done(void)
 
 /* ************************* init in-kernel code ************************** */
 
-static int __init savagefb_setup(char *options)
+static int __init savagefb_setup(const char *options)
 {
 #ifndef MODULE
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
@@ -2554,6 +2555,9 @@ static int __init savagefb_setup(char *options)
 			continue;
 		mode_option = mode_option_buf;
 	}
+
+	option_iter_release(&iter);
+
 #endif /* !MODULE */
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 71/99] fbdev/savagefb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/savage/savagefb_driver.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c
index 19fffe0b6cdd..94026848d67d 100644
--- a/drivers/video/fbdev/savage/savagefb_driver.c
+++ b/drivers/video/fbdev/savage/savagefb_driver.c
@@ -42,6 +42,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -2535,15 +2536,15 @@ static void __exit savage_done(void)
 
 /* ************************* init in-kernel code ************************** */
 
-static int __init savagefb_setup(char *options)
+static int __init savagefb_setup(const char *options)
 {
 #ifndef MODULE
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		static char mode_option_buf[256];
 		int ret;
 
@@ -2554,6 +2555,9 @@ static int __init savagefb_setup(char *options)
 			continue;
 		mode_option = mode_option_buf;
 	}
+
+	option_iter_release(&iter);
+
 #endif /* !MODULE */
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 72/99] fbdev/sisfb: Constify mode string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Constify the intenal video-mode string that is passed around among
functions. The caller owns the memory and callees do not modify its
content. This change will later allow to constify the option string.
No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sis/sis_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index cfba776afcea..c16493d3ac4f 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -73,7 +73,7 @@ static int	sisfb_blank(int blank,
 static void sisfb_handle_command(struct sis_video_info *ivideo,
 				 struct sisfb_cmd *sisfb_command);
 
-static void	sisfb_search_mode(char *name, bool quiet);
+static void	sisfb_search_mode(const char *name, bool quiet);
 static int	sisfb_validate_mode(struct sis_video_info *ivideo, int modeindex, u32 vbflags);
 static u8	sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate,
 				int index);
@@ -180,12 +180,12 @@ static void sisfb_search_vesamode(unsigned int vesamode, bool quiet)
 		printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode);
 }
 
-static void sisfb_search_mode(char *name, bool quiet)
+static void sisfb_search_mode(const char *name, bool quiet)
 {
 	unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0;
 	int i = 0;
 	char strbuf[16], strbuf1[20];
-	char *nameptr = name;
+	const char *nameptr = name;
 
 	/* We don't know the hardware specs yet and there is no ivideo */
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 72/99] fbdev/sisfb: Constify mode string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Constify the intenal video-mode string that is passed around among
functions. The caller owns the memory and callees do not modify its
content. This change will later allow to constify the option string.
No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sis/sis_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index cfba776afcea..c16493d3ac4f 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -73,7 +73,7 @@ static int	sisfb_blank(int blank,
 static void sisfb_handle_command(struct sis_video_info *ivideo,
 				 struct sisfb_cmd *sisfb_command);
 
-static void	sisfb_search_mode(char *name, bool quiet);
+static void	sisfb_search_mode(const char *name, bool quiet);
 static int	sisfb_validate_mode(struct sis_video_info *ivideo, int modeindex, u32 vbflags);
 static u8	sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate,
 				int index);
@@ -180,12 +180,12 @@ static void sisfb_search_vesamode(unsigned int vesamode, bool quiet)
 		printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode);
 }
 
-static void sisfb_search_mode(char *name, bool quiet)
+static void sisfb_search_mode(const char *name, bool quiet)
 {
 	unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0;
 	int i = 0;
 	char strbuf[16], strbuf1[20];
-	char *nameptr = name;
+	const char *nameptr = name;
 
 	/* We don't know the hardware specs yet and there is no ivideo */
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 73/99] fbdev/sisfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sis/sis_main.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index c16493d3ac4f..7e6e2251e62f 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -20,6 +20,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -54,7 +55,7 @@
 
 /* Interface used by the world */
 #ifndef MODULE
-static int sisfb_setup(char *options);
+static int sisfb_setup(const char *options);
 #endif
 
 /* Interface to the low level console driver */
@@ -3987,19 +3988,16 @@ sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_comm
 }
 
 #ifndef MODULE
-static int __init sisfb_setup(char *options)
+static int __init sisfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	sisfb_setdefaultparms();
 
-	if(!options || !(*options))
-		return 0;
-
-	while((this_opt = strsep(&options, ",")) != NULL) {
-
-		if(!(*this_opt)) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if(!strncasecmp(this_opt, "off", 3)) {
 			sisfb_off = 1;
 		} else if(!strncasecmp(this_opt, "forcecrt2type:", 14)) {
@@ -4081,6 +4079,8 @@ static int __init sisfb_setup(char *options)
 
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 73/99] fbdev/sisfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sis/sis_main.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index c16493d3ac4f..7e6e2251e62f 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -20,6 +20,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -54,7 +55,7 @@
 
 /* Interface used by the world */
 #ifndef MODULE
-static int sisfb_setup(char *options);
+static int sisfb_setup(const char *options);
 #endif
 
 /* Interface to the low level console driver */
@@ -3987,19 +3988,16 @@ sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_comm
 }
 
 #ifndef MODULE
-static int __init sisfb_setup(char *options)
+static int __init sisfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	sisfb_setdefaultparms();
 
-	if(!options || !(*options))
-		return 0;
-
-	while((this_opt = strsep(&options, ",")) != NULL) {
-
-		if(!(*this_opt)) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if(!strncasecmp(this_opt, "off", 3)) {
 			sisfb_off = 1;
 		} else if(!strncasecmp(this_opt, "forcecrt2type:", 14)) {
@@ -4081,6 +4079,8 @@ static int __init sisfb_setup(char *options)
 
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 74/99] fbdev/skeletonfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/skeletonfb.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/skeletonfb.c b/drivers/video/fbdev/skeletonfb.c
index 40c130ab6b38..1e876ad2a261 100644
--- a/drivers/video/fbdev/skeletonfb.c
+++ b/drivers/video/fbdev/skeletonfb.c
@@ -43,6 +43,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -973,9 +974,19 @@ static struct platform_device *xxxfb_device;
  * Only necessary if your driver takes special options,
  * otherwise we fall back on the generic fb_setup().
  */
-static int __init xxxfb_setup(char *options)
+static int __init xxxfb_setup(const char *options)
 {
-    /* Parse user specified options (`video=xxxfb:') */
+	/* Parse user-specified options (`video=xxxfb:') */
+
+	struct option_iter iter;
+	const char *this_opt;
+
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
+	}
+
+	option_iter_release(&iter);
 }
 #endif /* MODULE */
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 74/99] fbdev/skeletonfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/skeletonfb.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/skeletonfb.c b/drivers/video/fbdev/skeletonfb.c
index 40c130ab6b38..1e876ad2a261 100644
--- a/drivers/video/fbdev/skeletonfb.c
+++ b/drivers/video/fbdev/skeletonfb.c
@@ -43,6 +43,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -973,9 +974,19 @@ static struct platform_device *xxxfb_device;
  * Only necessary if your driver takes special options,
  * otherwise we fall back on the generic fb_setup().
  */
-static int __init xxxfb_setup(char *options)
+static int __init xxxfb_setup(const char *options)
 {
-    /* Parse user specified options (`video=xxxfb:') */
+	/* Parse user-specified options (`video=xxxfb:') */
+
+	struct option_iter iter;
+	const char *this_opt;
+
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, this_opt)) {
+	}
+
+	option_iter_release(&iter);
 }
 #endif /* MODULE */
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 75/99] fbdev/sm712fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sm712fb.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c
index b528776c7612..b0f3898125f4 100644
--- a/drivers/video/fbdev/sm712fb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -1761,8 +1761,21 @@ static int __init sm712fb_init(void)
 
 	if (fb_get_options("sm712fb", &option))
 		return -ENODEV;
-	if (option && *option)
-		mode_option = option;
+
+	if (option && *option) {
+		do {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
+			if (WARN(ret < 0, "sm712fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "sm712fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		} while (0);
+	}
+
 	sm7xx_vga_setup(mode_option);
 
 	return pci_register_driver(&smtcfb_driver);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 75/99] fbdev/sm712fb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sm712fb.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c
index b528776c7612..b0f3898125f4 100644
--- a/drivers/video/fbdev/sm712fb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -1761,8 +1761,21 @@ static int __init sm712fb_init(void)
 
 	if (fb_get_options("sm712fb", &option))
 		return -ENODEV;
-	if (option && *option)
-		mode_option = option;
+
+	if (option && *option) {
+		do {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
+			if (WARN(ret < 0, "sm712fb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "sm712fb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		} while (0);
+	}
+
 	sm7xx_vga_setup(mode_option);
 
 	return pci_register_driver(&smtcfb_driver);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 76/99] fbdev/sstfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sstfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index da296b2ab54a..7cd65f924b08 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -1301,8 +1301,17 @@ static int sstfb_setup(char *options)
 			mem = simple_strtoul (this_opt+4, NULL, 0);
 		else if (!strncmp(this_opt, "gfxclk:",7))
 			gfxclk = simple_strtoul (this_opt+7, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "sstfb: Ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "sstfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 76/99] fbdev/sstfb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sstfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index da296b2ab54a..7cd65f924b08 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -1301,8 +1301,17 @@ static int sstfb_setup(char *options)
 			mem = simple_strtoul (this_opt+4, NULL, 0);
 		else if (!strncmp(this_opt, "gfxclk:",7))
 			gfxclk = simple_strtoul (this_opt+7, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "sstfb: Ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "sstfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 77/99] fbdev/sstfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sstfb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index 7cd65f924b08..6c3769062d50 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -81,6 +81,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -1273,16 +1274,14 @@ static void sst_shutdown(struct fb_info *info)
 /*
  * Interface to the world
  */
-static int sstfb_setup(char *options)
+static int sstfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		f_ddprintk("option %s\n", this_opt);
 
 		if (!strcmp(this_opt, "vganopass"))
@@ -1313,6 +1312,9 @@ static int sstfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 77/99] fbdev/sstfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/sstfb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index 7cd65f924b08..6c3769062d50 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -81,6 +81,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -1273,16 +1274,14 @@ static void sst_shutdown(struct fb_info *info)
 /*
  * Interface to the world
  */
-static int sstfb_setup(char *options)
+static int sstfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		f_ddprintk("option %s\n", this_opt);
 
 		if (!strcmp(this_opt, "vganopass"))
@@ -1313,6 +1312,9 @@ static int sstfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 78/99] fbdev/stifb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/stifb.c | 156 ++++++++++++++++++------------------
 1 file changed, 78 insertions(+), 78 deletions(-)

diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index 3feb6e40d56d..a151377f5b45 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -1,11 +1,11 @@
 /*
- * linux/drivers/video/stifb.c - 
- * Low level Frame buffer driver for HP workstations with 
+ * linux/drivers/video/stifb.c -
+ * Low level Frame buffer driver for HP workstations with
  * STI (standard text interface) video firmware.
  *
  * Copyright (C) 2001-2006 Helge Deller <deller@gmx.de>
  * Portions Copyright (C) 2001 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
- * 
+ *
  * Based on:
  * - linux/drivers/video/artistfb.c -- Artist frame buffer driver
  *	Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
@@ -14,7 +14,7 @@
  * - HP Xhp cfb-based X11 window driver for XFree86
  *	(c)Copyright 1992 Hewlett-Packard Co.
  *
- * 
+ *
  *  The following graphics display devices (NGLE family) are supported by this driver:
  *
  *  HPA4070A	known as "HCRX", a 1280x1024 color device with 8 planes
@@ -30,7 +30,7 @@
  *		supports 1280x1024 color displays with 8 planes.
  *  HP710G	same as HP710C, 1280x1024 grayscale only
  *  HP710L	same as HP710C, 1024x768 color only
- *  HP712	internal graphics support on HP9000s712 SPU, supports 640x480, 
+ *  HP712	internal graphics support on HP9000s712 SPU, supports 640x480,
  *		1024x768 or 1280x1024 color displays on 8 planes (Artist)
  *
  * This file is subject to the terms and conditions of the GNU General Public
@@ -92,7 +92,7 @@ typedef struct {
 	__s32	misc_video_end;
 } video_setup_t;
 
-typedef struct {                  
+typedef struct {
 	__s16	sizeof_ngle_data;
 	__s16	x_size_visible;	    /* visible screen dim in pixels  */
 	__s16	y_size_visible;
@@ -177,10 +177,10 @@ static int __initdata stifb_bpp_pref[MAX_STI_ROMS];
 #endif /* DEBUG_STIFB_REGS */
 
 
-#define ENABLE	1	/* for enabling/disabling screen */	
+#define ENABLE	1	/* for enabling/disabling screen */
 #define DISABLE 0
 
-#define NGLE_LOCK(fb_info)	do { } while (0) 
+#define NGLE_LOCK(fb_info)	do { } while (0)
 #define NGLE_UNLOCK(fb_info)	do { } while (0)
 
 static void
@@ -198,9 +198,9 @@ SETUP_HW(struct stifb_info *fb)
 
 static void
 SETUP_FB(struct stifb_info *fb)
-{	
+{
 	unsigned int reg10_value = 0;
-	
+
 	SETUP_HW(fb);
 	switch (fb->id)
 	{
@@ -210,15 +210,15 @@ SETUP_FB(struct stifb_info *fb)
 			reg10_value = 0x13601000;
 			break;
 		case S9000_ID_A1439A:
-			if (fb->info.var.bits_per_pixel == 32)						
+			if (fb->info.var.bits_per_pixel == 32)
 				reg10_value = 0xBBA0A000;
-			else 
+			else
 				reg10_value = 0x13601000;
 			break;
 		case S9000_ID_HCRX:
 			if (fb->info.var.bits_per_pixel == 32)
 				reg10_value = 0xBBA0A000;
-			else					
+			else
 				reg10_value = 0x13602000;
 			break;
 		case S9000_ID_TIMBER:
@@ -243,7 +243,7 @@ START_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb)
 }
 
 static void
-WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color) 
+WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(((0x100+index)<<2), fb, REG_3);
@@ -251,30 +251,30 @@ WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color)
 }
 
 static void
-FINISH_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb) 
-{		
+FINISH_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb)
+{
 	WRITE_WORD(0x400, fb, REG_2);
 	if (fb->info.var.bits_per_pixel == 32) {
 		WRITE_WORD(0x83000100, fb, REG_1);
 	} else {
 		if (fb->id == S9000_ID_ARTIST || fb->id == CRT_ID_VISUALIZE_EG)
 			WRITE_WORD(0x80000100, fb, REG_26);
-		else							
+		else
 			WRITE_WORD(0x80000100, fb, REG_1);
 	}
 	SETUP_FB(fb);
 }
 
 static void
-SETUP_RAMDAC(struct stifb_info *fb) 
+SETUP_RAMDAC(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(0x04000000, fb, 0x1020);
 	WRITE_WORD(0xff000000, fb, 0x1028);
 }
 
-static void 
-CRX24_SETUP_RAMDAC(struct stifb_info *fb) 
+static void
+CRX24_SETUP_RAMDAC(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(0x04000000, fb, 0x1000);
@@ -286,14 +286,14 @@ CRX24_SETUP_RAMDAC(struct stifb_info *fb)
 }
 
 #if 0
-static void 
+static void
 HCRX_SETUP_RAMDAC(struct stifb_info *fb)
 {
 	WRITE_WORD(0xffffffff, fb, REG_32);
 }
 #endif
 
-static void 
+static void
 CRX24_SET_OVLY_MASK(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
@@ -314,7 +314,7 @@ ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
         WRITE_WORD(value, 	fb, 0x1038);
 }
 
-static void 
+static void
 CRX24_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 {
 	unsigned int value = enable ? 0x10000000 : 0x30000000;
@@ -325,11 +325,11 @@ CRX24_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 }
 
 static void
-ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable) 
+ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 {
 	u32 DregsMiscVideo = REG_21;
 	u32 DregsMiscCtl = REG_27;
-	
+
 	SETUP_HW(fb);
 	if (enable) {
 	  WRITE_WORD(READ_WORD(fb, DregsMiscVideo) | 0x0A000000, fb, DregsMiscVideo);
@@ -344,7 +344,7 @@ ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 	(READ_BYTE(fb, REG_16b3) - 1)
 
 #define HYPER_CONFIG_PLANES_24 0x00000100
-	
+
 #define IS_24_DEVICE(fb) \
 	(fb->deviceSpecificConfig & HYPER_CONFIG_PLANES_24)
 
@@ -470,15 +470,15 @@ SETUP_ATTR_ACCESS(struct stifb_info *fb, unsigned BufferNumber)
 }
 
 static void
-SET_ATTR_SIZE(struct stifb_info *fb, int width, int height) 
+SET_ATTR_SIZE(struct stifb_info *fb, int width, int height)
 {
-	/* REG_6 seems to have special values when run on a 
+	/* REG_6 seems to have special values when run on a
 	   RDI precisionbook parisc laptop (INTERNAL_EG_DX1024 or
 	   INTERNAL_EG_X1024).  The values are:
 		0x2f0: internal (LCD) & external display enabled
 		0x2a0: external display only
 		0x000: zero on standard artist graphic cards
-	*/ 
+	*/
 	WRITE_WORD(0x00000000, fb, REG_6);
 	WRITE_WORD((width<<16) | height, fb, REG_9);
 	WRITE_WORD(0x05000000, fb, REG_6);
@@ -486,7 +486,7 @@ SET_ATTR_SIZE(struct stifb_info *fb, int width, int height)
 }
 
 static void
-FINISH_ATTR_ACCESS(struct stifb_info *fb) 
+FINISH_ATTR_ACCESS(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(0x00000000, fb, REG_12);
@@ -499,7 +499,7 @@ elkSetupPlanes(struct stifb_info *fb)
 	SETUP_FB(fb);
 }
 
-static void 
+static void
 ngleSetupAttrPlanes(struct stifb_info *fb, int BufferNumber)
 {
 	SETUP_ATTR_ACCESS(fb, BufferNumber);
@@ -519,7 +519,7 @@ rattlerSetupPlanes(struct stifb_info *fb)
 	 * read mask register for overlay planes, not image planes).
 	 */
 	CRX24_SETUP_RAMDAC(fb);
-    
+
 	/* change fb->id temporarily to fool SETUP_FB() */
 	saved_id = fb->id;
 	fb->id = CRX24_OVERLAY_PLANES;
@@ -565,7 +565,7 @@ setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 	lutBltCtl.all           = 0x80000000;
 	lutBltCtl.fields.length = length;
 
-	switch (fb->id) 
+	switch (fb->id)
 	{
 	case S9000_ID_A1439A:		/* CRX24 */
 		if (fb->var.bits_per_pixel == 8) {
@@ -576,12 +576,12 @@ setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 			lutBltCtl.fields.lutOffset = 0 * 256;
 		}
 		break;
-		
+
 	case S9000_ID_ARTIST:
 		lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
 		lutBltCtl.fields.lutOffset = 0 * 256;
 		break;
-		
+
 	default:
 		lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
 		lutBltCtl.fields.lutOffset = 0;
@@ -596,7 +596,7 @@ setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 #endif
 
 static NgleLutBltCtl
-setHyperLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length) 
+setHyperLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 {
 	NgleLutBltCtl lutBltCtl;
 
@@ -633,7 +633,7 @@ static void hyperUndoITE(struct stifb_info *fb)
 
 	/* Hardware setup for full-depth write to "magic" location */
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 7);
-	NGLE_QUICK_SET_DST_BM_ACCESS(fb, 
+	NGLE_QUICK_SET_DST_BM_ACCESS(fb,
 		BA(IndexedDcd, Otc04, Ots08, AddrLong,
 		BAJustPoint(0), BINovly, BAIndexBase(0)));
 	NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
@@ -653,13 +653,13 @@ static void hyperUndoITE(struct stifb_info *fb)
 	NGLE_UNLOCK(fb);
 }
 
-static void 
+static void
 ngleDepth8_ClearImagePlanes(struct stifb_info *fb)
 {
 	/* FIXME! */
 }
 
-static void 
+static void
 ngleDepth24_ClearImagePlanes(struct stifb_info *fb)
 {
 	/* FIXME! */
@@ -675,7 +675,7 @@ ngleResetAttrPlanes(struct stifb_info *fb, unsigned int ctlPlaneReg)
 	NGLE_LOCK(fb);
 
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 4);
-	NGLE_QUICK_SET_DST_BM_ACCESS(fb, 
+	NGLE_QUICK_SET_DST_BM_ACCESS(fb,
 				     BA(IndexedDcd, Otc32, OtsIndirect,
 					AddrLong, BAJustPoint(0),
 					BINattr, BAIndexBase(0)));
@@ -713,22 +713,22 @@ ngleResetAttrPlanes(struct stifb_info *fb, unsigned int ctlPlaneReg)
 	/**** Finally, set the Control Plane Register back to zero: ****/
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 1);
 	NGLE_QUICK_SET_CTL_PLN_REG(fb, 0);
-	
+
 	NGLE_UNLOCK(fb);
 }
-    
+
 static void
 ngleClearOverlayPlanes(struct stifb_info *fb, int mask, int data)
 {
 	int nFreeFifoSlots = 0;
 	u32 packed_dst;
 	u32 packed_len;
-    
+
 	NGLE_LOCK(fb);
 
 	/* Hardware setup */
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 8);
-	NGLE_QUICK_SET_DST_BM_ACCESS(fb, 
+	NGLE_QUICK_SET_DST_BM_ACCESS(fb,
 				     BA(IndexedDcd, Otc04, Ots08, AddrLong,
 					BAJustPoint(0), BINovly, BAIndexBase(0)));
 
@@ -736,23 +736,23 @@ ngleClearOverlayPlanes(struct stifb_info *fb, int mask, int data)
 
         NGLE_REALLY_SET_IMAGE_FG_COLOR(fb, data);
         NGLE_REALLY_SET_IMAGE_PLANEMASK(fb, mask);
-    
+
         packed_dst = 0;
         packed_len = (fb->info.var.xres << 16) | fb->info.var.yres;
         NGLE_SET_DSTXY(fb, packed_dst);
-    
-        /* Write zeroes to overlay planes */		       
+
+        /* Write zeroes to overlay planes */
 	NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
 				       IBOvals(RopSrc, MaskAddrOffset(0),
 					       BitmapExtent08, StaticReg(0),
 					       DataDynamic, MaskOtc, BGx(0), FGx(0)));
-		       
+
         SET_LENXY_START_RECFILL(fb, packed_len);
 
 	NGLE_UNLOCK(fb);
 }
 
-static void 
+static void
 hyperResetPlanes(struct stifb_info *fb, int enable)
 {
 	unsigned int controlPlaneReg;
@@ -783,7 +783,7 @@ hyperResetPlanes(struct stifb_info *fb, int enable)
 	        ngleClearOverlayPlanes(fb, 0xff, 255);
 
 		/**************************************************
-		 ** Also need to counteract ITE settings 
+		 ** Also need to counteract ITE settings
 		 **************************************************/
 		hyperUndoITE(fb);
 		break;
@@ -803,13 +803,13 @@ hyperResetPlanes(struct stifb_info *fb, int enable)
 		ngleResetAttrPlanes(fb, controlPlaneReg);
 		break;
     	}
-	
+
 	NGLE_UNLOCK(fb);
 }
 
 /* Return pointer to in-memory structure holding ELK device-dependent ROM values. */
 
-static void 
+static void
 ngleGetDeviceRomData(struct stifb_info *fb)
 {
 #if 0
@@ -821,7 +821,7 @@ XXX: FIXME: !!!
 	char	*pCard8;
 	int	i;
 	char	*mapOrigin = NULL;
-    
+
 	int romTableIdx;
 
 	pPackedDevRomData = fb->ngle_rom;
@@ -888,7 +888,7 @@ SETUP_HCRX(struct stifb_info *fb)
 
 	/* Initialize Hyperbowl registers */
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 7);
-	
+
 	if (IS_24_DEVICE(fb)) {
 		hyperbowl = (fb->info.var.bits_per_pixel == 32) ?
 			HYPERBOWL_MODE01_8_24_LUT0_TRANSPARENT_LUT1_OPAQUE :
@@ -897,9 +897,9 @@ SETUP_HCRX(struct stifb_info *fb)
 		/* First write to Hyperbowl must happen twice (bug) */
 		WRITE_WORD(hyperbowl, fb, REG_40);
 		WRITE_WORD(hyperbowl, fb, REG_40);
-		
+
 		WRITE_WORD(HYPERBOWL_MODE2_8_24, fb, REG_39);
-		
+
 		WRITE_WORD(0x014c0148, fb, REG_42); /* Set lut 0 to be the direct color */
 		WRITE_WORD(0x404c4048, fb, REG_43);
 		WRITE_WORD(0x034c0348, fb, REG_44);
@@ -968,7 +968,7 @@ stifb_setcolreg(u_int regno, u_int red, u_int green,
 				0,	/* Offset w/i LUT */
 				256);	/* Load entire LUT */
 		NGLE_BINC_SET_SRCADDR(fb,
-				NGLE_LONG_FB_ADDRESS(0, 0x100, 0)); 
+				NGLE_LONG_FB_ADDRESS(0, 0x100, 0));
 				/* 0x100 is same as used in WRITE_IMAGE_COLOR() */
 		START_COLORMAPLOAD(fb, lutBltCtl.all);
 		SETUP_FB(fb);
@@ -1006,7 +1006,7 @@ stifb_blank(int blank_mode, struct fb_info *info)
 		ENABLE_DISABLE_DISPLAY(fb, enable);
 		break;
 	}
-	
+
 	SETUP_FB(fb);
 	return 0;
 }
@@ -1092,15 +1092,15 @@ stifb_init_display(struct stifb_info *fb)
 
 	/* HCRX specific initialization */
 	SETUP_HCRX(fb);
-	
+
 	/*
 	if (id == S9000_ID_HCRX)
 		hyperInitSprite(fb);
 	else
 		ngleInitSprite(fb);
 	*/
-	
-	/* Initialize the image planes. */ 
+
+	/* Initialize the image planes. */
         switch (id) {
 	 case S9000_ID_HCRX:
 	    hyperResetPlanes(fb, ENABLE);
@@ -1170,7 +1170,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	fb = kzalloc(sizeof(*fb), GFP_ATOMIC);
 	if (!fb)
 		return -ENOMEM;
-	
+
 	info = &fb->info;
 
 	/* set struct to a known state */
@@ -1211,7 +1211,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 			dev_name, fb->id);
 		goto out_err0;
 	}
-	
+
 	/* default to 8 bpp on most graphic chips */
 	bpp = 8;
 	xres = sti_onscreen_x(fb->sti);
@@ -1232,7 +1232,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 		fb->id = S9000_ID_A1659A;
 		break;
 	case S9000_ID_TIMBER:	/* HP9000/710 Any (may be a grayscale device) */
-		if (strstr(dev_name, "GRAYSCALE") || 
+		if (strstr(dev_name, "GRAYSCALE") ||
 		    strstr(dev_name, "Grayscale") ||
 		    strstr(dev_name, "grayscale"))
 			var->grayscale = 1;
@@ -1271,16 +1271,16 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	case CRT_ID_VISUALIZE_EG:
 	case S9000_ID_ARTIST:	/* Artist */
 		break;
-	default: 
+	default:
 #ifdef FALLBACK_TO_1BPP
-	       	printk(KERN_WARNING 
+	       	printk(KERN_WARNING
 			"stifb: Unsupported graphics card (id=0x%08x) "
 				"- now trying 1bpp mode instead\n",
 			fb->id);
 		bpp = 1;	/* default to 1 bpp */
 		break;
 #else
-	       	printk(KERN_WARNING 
+	       	printk(KERN_WARNING
 			"stifb: Unsupported graphics card (id=0x%08x) "
 				"- skipping.\n",
 			fb->id);
@@ -1296,11 +1296,11 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	fix->line_length = (fb->sti->glob_cfg->total_x * bpp) / 8;
 	if (!fix->line_length)
 		fix->line_length = 2048; /* default */
-	
+
 	/* limit fbsize to max visible screen size */
 	if (fix->smem_len > yres*fix->line_length)
 		fix->smem_len = ALIGN(yres*fix->line_length, 4*1024*1024);
-	
+
 	fix->accel = FB_ACCEL_NONE;
 
 	switch (bpp) {
@@ -1326,7 +1326,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	    default:
 		break;
 	}
-	
+
 	var->xres = var->xres_virtual = xres;
 	var->yres = var->yres_virtual = yres;
 	var->bits_per_pixel = bpp;
@@ -1352,7 +1352,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 				fix->smem_start, fix->smem_start+fix->smem_len);
 		goto out_err2;
 	}
-		
+
 	if (!request_mem_region(fix->mmio_start, fix->mmio_len, "stifb mmio")) {
 		printk(KERN_ERR "stifb: cannot reserve sti mmio region 0x%04lx-0x%04lx\n",
 				fix->mmio_start, fix->mmio_start+fix->mmio_len);
@@ -1366,11 +1366,11 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 
 	fb_info(&fb->info, "%s %dx%d-%d frame buffer device, %s, id: %04x, mmio: 0x%04lx\n",
 		fix->id,
-		var->xres, 
+		var->xres,
 		var->yres,
 		var->bits_per_pixel,
 		dev_name,
-		fb->id, 
+		fb->id,
 		fix->mmio_start);
 
 	return 0;
@@ -1399,7 +1399,7 @@ static int __init stifb_init(void)
 	struct sti_struct *sti;
 	struct sti_struct *def_sti;
 	int i;
-	
+
 #ifndef MODULE
 	char *option = NULL;
 
@@ -1411,7 +1411,7 @@ static int __init stifb_init(void)
 		printk(KERN_INFO "stifb: disabled by \"stifb=off\" kernel parameter\n");
 		return -ENXIO;
 	}
-	
+
 	def_sti = sti_get_rom(0);
 	if (def_sti) {
 		for (i = 1; i <= MAX_STI_ROMS; i++) {
@@ -1445,7 +1445,7 @@ stifb_cleanup(void)
 {
 	struct sti_struct *sti;
 	int i;
-	
+
 	for (i = 1; i <= MAX_STI_ROMS; i++) {
 		sti = sti_get_rom(i);
 		if (!sti)
@@ -1468,10 +1468,10 @@ int __init
 stifb_setup(char *options)
 {
 	int i;
-	
+
 	if (!options || !*options)
 		return 1;
-	
+
 	if (strncmp(options, "off", 3) == 0) {
 		stifb_disabled = 1;
 		options += 3;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 78/99] fbdev/stifb: Remove trailing whitespaces
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/stifb.c | 156 ++++++++++++++++++------------------
 1 file changed, 78 insertions(+), 78 deletions(-)

diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index 3feb6e40d56d..a151377f5b45 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -1,11 +1,11 @@
 /*
- * linux/drivers/video/stifb.c - 
- * Low level Frame buffer driver for HP workstations with 
+ * linux/drivers/video/stifb.c -
+ * Low level Frame buffer driver for HP workstations with
  * STI (standard text interface) video firmware.
  *
  * Copyright (C) 2001-2006 Helge Deller <deller@gmx.de>
  * Portions Copyright (C) 2001 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
- * 
+ *
  * Based on:
  * - linux/drivers/video/artistfb.c -- Artist frame buffer driver
  *	Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
@@ -14,7 +14,7 @@
  * - HP Xhp cfb-based X11 window driver for XFree86
  *	(c)Copyright 1992 Hewlett-Packard Co.
  *
- * 
+ *
  *  The following graphics display devices (NGLE family) are supported by this driver:
  *
  *  HPA4070A	known as "HCRX", a 1280x1024 color device with 8 planes
@@ -30,7 +30,7 @@
  *		supports 1280x1024 color displays with 8 planes.
  *  HP710G	same as HP710C, 1280x1024 grayscale only
  *  HP710L	same as HP710C, 1024x768 color only
- *  HP712	internal graphics support on HP9000s712 SPU, supports 640x480, 
+ *  HP712	internal graphics support on HP9000s712 SPU, supports 640x480,
  *		1024x768 or 1280x1024 color displays on 8 planes (Artist)
  *
  * This file is subject to the terms and conditions of the GNU General Public
@@ -92,7 +92,7 @@ typedef struct {
 	__s32	misc_video_end;
 } video_setup_t;
 
-typedef struct {                  
+typedef struct {
 	__s16	sizeof_ngle_data;
 	__s16	x_size_visible;	    /* visible screen dim in pixels  */
 	__s16	y_size_visible;
@@ -177,10 +177,10 @@ static int __initdata stifb_bpp_pref[MAX_STI_ROMS];
 #endif /* DEBUG_STIFB_REGS */
 
 
-#define ENABLE	1	/* for enabling/disabling screen */	
+#define ENABLE	1	/* for enabling/disabling screen */
 #define DISABLE 0
 
-#define NGLE_LOCK(fb_info)	do { } while (0) 
+#define NGLE_LOCK(fb_info)	do { } while (0)
 #define NGLE_UNLOCK(fb_info)	do { } while (0)
 
 static void
@@ -198,9 +198,9 @@ SETUP_HW(struct stifb_info *fb)
 
 static void
 SETUP_FB(struct stifb_info *fb)
-{	
+{
 	unsigned int reg10_value = 0;
-	
+
 	SETUP_HW(fb);
 	switch (fb->id)
 	{
@@ -210,15 +210,15 @@ SETUP_FB(struct stifb_info *fb)
 			reg10_value = 0x13601000;
 			break;
 		case S9000_ID_A1439A:
-			if (fb->info.var.bits_per_pixel == 32)						
+			if (fb->info.var.bits_per_pixel == 32)
 				reg10_value = 0xBBA0A000;
-			else 
+			else
 				reg10_value = 0x13601000;
 			break;
 		case S9000_ID_HCRX:
 			if (fb->info.var.bits_per_pixel == 32)
 				reg10_value = 0xBBA0A000;
-			else					
+			else
 				reg10_value = 0x13602000;
 			break;
 		case S9000_ID_TIMBER:
@@ -243,7 +243,7 @@ START_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb)
 }
 
 static void
-WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color) 
+WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(((0x100+index)<<2), fb, REG_3);
@@ -251,30 +251,30 @@ WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color)
 }
 
 static void
-FINISH_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb) 
-{		
+FINISH_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb)
+{
 	WRITE_WORD(0x400, fb, REG_2);
 	if (fb->info.var.bits_per_pixel == 32) {
 		WRITE_WORD(0x83000100, fb, REG_1);
 	} else {
 		if (fb->id == S9000_ID_ARTIST || fb->id == CRT_ID_VISUALIZE_EG)
 			WRITE_WORD(0x80000100, fb, REG_26);
-		else							
+		else
 			WRITE_WORD(0x80000100, fb, REG_1);
 	}
 	SETUP_FB(fb);
 }
 
 static void
-SETUP_RAMDAC(struct stifb_info *fb) 
+SETUP_RAMDAC(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(0x04000000, fb, 0x1020);
 	WRITE_WORD(0xff000000, fb, 0x1028);
 }
 
-static void 
-CRX24_SETUP_RAMDAC(struct stifb_info *fb) 
+static void
+CRX24_SETUP_RAMDAC(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(0x04000000, fb, 0x1000);
@@ -286,14 +286,14 @@ CRX24_SETUP_RAMDAC(struct stifb_info *fb)
 }
 
 #if 0
-static void 
+static void
 HCRX_SETUP_RAMDAC(struct stifb_info *fb)
 {
 	WRITE_WORD(0xffffffff, fb, REG_32);
 }
 #endif
 
-static void 
+static void
 CRX24_SET_OVLY_MASK(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
@@ -314,7 +314,7 @@ ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
         WRITE_WORD(value, 	fb, 0x1038);
 }
 
-static void 
+static void
 CRX24_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 {
 	unsigned int value = enable ? 0x10000000 : 0x30000000;
@@ -325,11 +325,11 @@ CRX24_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 }
 
 static void
-ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable) 
+ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 {
 	u32 DregsMiscVideo = REG_21;
 	u32 DregsMiscCtl = REG_27;
-	
+
 	SETUP_HW(fb);
 	if (enable) {
 	  WRITE_WORD(READ_WORD(fb, DregsMiscVideo) | 0x0A000000, fb, DregsMiscVideo);
@@ -344,7 +344,7 @@ ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
 	(READ_BYTE(fb, REG_16b3) - 1)
 
 #define HYPER_CONFIG_PLANES_24 0x00000100
-	
+
 #define IS_24_DEVICE(fb) \
 	(fb->deviceSpecificConfig & HYPER_CONFIG_PLANES_24)
 
@@ -470,15 +470,15 @@ SETUP_ATTR_ACCESS(struct stifb_info *fb, unsigned BufferNumber)
 }
 
 static void
-SET_ATTR_SIZE(struct stifb_info *fb, int width, int height) 
+SET_ATTR_SIZE(struct stifb_info *fb, int width, int height)
 {
-	/* REG_6 seems to have special values when run on a 
+	/* REG_6 seems to have special values when run on a
 	   RDI precisionbook parisc laptop (INTERNAL_EG_DX1024 or
 	   INTERNAL_EG_X1024).  The values are:
 		0x2f0: internal (LCD) & external display enabled
 		0x2a0: external display only
 		0x000: zero on standard artist graphic cards
-	*/ 
+	*/
 	WRITE_WORD(0x00000000, fb, REG_6);
 	WRITE_WORD((width<<16) | height, fb, REG_9);
 	WRITE_WORD(0x05000000, fb, REG_6);
@@ -486,7 +486,7 @@ SET_ATTR_SIZE(struct stifb_info *fb, int width, int height)
 }
 
 static void
-FINISH_ATTR_ACCESS(struct stifb_info *fb) 
+FINISH_ATTR_ACCESS(struct stifb_info *fb)
 {
 	SETUP_HW(fb);
 	WRITE_WORD(0x00000000, fb, REG_12);
@@ -499,7 +499,7 @@ elkSetupPlanes(struct stifb_info *fb)
 	SETUP_FB(fb);
 }
 
-static void 
+static void
 ngleSetupAttrPlanes(struct stifb_info *fb, int BufferNumber)
 {
 	SETUP_ATTR_ACCESS(fb, BufferNumber);
@@ -519,7 +519,7 @@ rattlerSetupPlanes(struct stifb_info *fb)
 	 * read mask register for overlay planes, not image planes).
 	 */
 	CRX24_SETUP_RAMDAC(fb);
-    
+
 	/* change fb->id temporarily to fool SETUP_FB() */
 	saved_id = fb->id;
 	fb->id = CRX24_OVERLAY_PLANES;
@@ -565,7 +565,7 @@ setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 	lutBltCtl.all           = 0x80000000;
 	lutBltCtl.fields.length = length;
 
-	switch (fb->id) 
+	switch (fb->id)
 	{
 	case S9000_ID_A1439A:		/* CRX24 */
 		if (fb->var.bits_per_pixel == 8) {
@@ -576,12 +576,12 @@ setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 			lutBltCtl.fields.lutOffset = 0 * 256;
 		}
 		break;
-		
+
 	case S9000_ID_ARTIST:
 		lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
 		lutBltCtl.fields.lutOffset = 0 * 256;
 		break;
-		
+
 	default:
 		lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
 		lutBltCtl.fields.lutOffset = 0;
@@ -596,7 +596,7 @@ setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 #endif
 
 static NgleLutBltCtl
-setHyperLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length) 
+setHyperLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
 {
 	NgleLutBltCtl lutBltCtl;
 
@@ -633,7 +633,7 @@ static void hyperUndoITE(struct stifb_info *fb)
 
 	/* Hardware setup for full-depth write to "magic" location */
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 7);
-	NGLE_QUICK_SET_DST_BM_ACCESS(fb, 
+	NGLE_QUICK_SET_DST_BM_ACCESS(fb,
 		BA(IndexedDcd, Otc04, Ots08, AddrLong,
 		BAJustPoint(0), BINovly, BAIndexBase(0)));
 	NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
@@ -653,13 +653,13 @@ static void hyperUndoITE(struct stifb_info *fb)
 	NGLE_UNLOCK(fb);
 }
 
-static void 
+static void
 ngleDepth8_ClearImagePlanes(struct stifb_info *fb)
 {
 	/* FIXME! */
 }
 
-static void 
+static void
 ngleDepth24_ClearImagePlanes(struct stifb_info *fb)
 {
 	/* FIXME! */
@@ -675,7 +675,7 @@ ngleResetAttrPlanes(struct stifb_info *fb, unsigned int ctlPlaneReg)
 	NGLE_LOCK(fb);
 
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 4);
-	NGLE_QUICK_SET_DST_BM_ACCESS(fb, 
+	NGLE_QUICK_SET_DST_BM_ACCESS(fb,
 				     BA(IndexedDcd, Otc32, OtsIndirect,
 					AddrLong, BAJustPoint(0),
 					BINattr, BAIndexBase(0)));
@@ -713,22 +713,22 @@ ngleResetAttrPlanes(struct stifb_info *fb, unsigned int ctlPlaneReg)
 	/**** Finally, set the Control Plane Register back to zero: ****/
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 1);
 	NGLE_QUICK_SET_CTL_PLN_REG(fb, 0);
-	
+
 	NGLE_UNLOCK(fb);
 }
-    
+
 static void
 ngleClearOverlayPlanes(struct stifb_info *fb, int mask, int data)
 {
 	int nFreeFifoSlots = 0;
 	u32 packed_dst;
 	u32 packed_len;
-    
+
 	NGLE_LOCK(fb);
 
 	/* Hardware setup */
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 8);
-	NGLE_QUICK_SET_DST_BM_ACCESS(fb, 
+	NGLE_QUICK_SET_DST_BM_ACCESS(fb,
 				     BA(IndexedDcd, Otc04, Ots08, AddrLong,
 					BAJustPoint(0), BINovly, BAIndexBase(0)));
 
@@ -736,23 +736,23 @@ ngleClearOverlayPlanes(struct stifb_info *fb, int mask, int data)
 
         NGLE_REALLY_SET_IMAGE_FG_COLOR(fb, data);
         NGLE_REALLY_SET_IMAGE_PLANEMASK(fb, mask);
-    
+
         packed_dst = 0;
         packed_len = (fb->info.var.xres << 16) | fb->info.var.yres;
         NGLE_SET_DSTXY(fb, packed_dst);
-    
-        /* Write zeroes to overlay planes */		       
+
+        /* Write zeroes to overlay planes */
 	NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
 				       IBOvals(RopSrc, MaskAddrOffset(0),
 					       BitmapExtent08, StaticReg(0),
 					       DataDynamic, MaskOtc, BGx(0), FGx(0)));
-		       
+
         SET_LENXY_START_RECFILL(fb, packed_len);
 
 	NGLE_UNLOCK(fb);
 }
 
-static void 
+static void
 hyperResetPlanes(struct stifb_info *fb, int enable)
 {
 	unsigned int controlPlaneReg;
@@ -783,7 +783,7 @@ hyperResetPlanes(struct stifb_info *fb, int enable)
 	        ngleClearOverlayPlanes(fb, 0xff, 255);
 
 		/**************************************************
-		 ** Also need to counteract ITE settings 
+		 ** Also need to counteract ITE settings
 		 **************************************************/
 		hyperUndoITE(fb);
 		break;
@@ -803,13 +803,13 @@ hyperResetPlanes(struct stifb_info *fb, int enable)
 		ngleResetAttrPlanes(fb, controlPlaneReg);
 		break;
     	}
-	
+
 	NGLE_UNLOCK(fb);
 }
 
 /* Return pointer to in-memory structure holding ELK device-dependent ROM values. */
 
-static void 
+static void
 ngleGetDeviceRomData(struct stifb_info *fb)
 {
 #if 0
@@ -821,7 +821,7 @@ XXX: FIXME: !!!
 	char	*pCard8;
 	int	i;
 	char	*mapOrigin = NULL;
-    
+
 	int romTableIdx;
 
 	pPackedDevRomData = fb->ngle_rom;
@@ -888,7 +888,7 @@ SETUP_HCRX(struct stifb_info *fb)
 
 	/* Initialize Hyperbowl registers */
 	GET_FIFO_SLOTS(fb, nFreeFifoSlots, 7);
-	
+
 	if (IS_24_DEVICE(fb)) {
 		hyperbowl = (fb->info.var.bits_per_pixel == 32) ?
 			HYPERBOWL_MODE01_8_24_LUT0_TRANSPARENT_LUT1_OPAQUE :
@@ -897,9 +897,9 @@ SETUP_HCRX(struct stifb_info *fb)
 		/* First write to Hyperbowl must happen twice (bug) */
 		WRITE_WORD(hyperbowl, fb, REG_40);
 		WRITE_WORD(hyperbowl, fb, REG_40);
-		
+
 		WRITE_WORD(HYPERBOWL_MODE2_8_24, fb, REG_39);
-		
+
 		WRITE_WORD(0x014c0148, fb, REG_42); /* Set lut 0 to be the direct color */
 		WRITE_WORD(0x404c4048, fb, REG_43);
 		WRITE_WORD(0x034c0348, fb, REG_44);
@@ -968,7 +968,7 @@ stifb_setcolreg(u_int regno, u_int red, u_int green,
 				0,	/* Offset w/i LUT */
 				256);	/* Load entire LUT */
 		NGLE_BINC_SET_SRCADDR(fb,
-				NGLE_LONG_FB_ADDRESS(0, 0x100, 0)); 
+				NGLE_LONG_FB_ADDRESS(0, 0x100, 0));
 				/* 0x100 is same as used in WRITE_IMAGE_COLOR() */
 		START_COLORMAPLOAD(fb, lutBltCtl.all);
 		SETUP_FB(fb);
@@ -1006,7 +1006,7 @@ stifb_blank(int blank_mode, struct fb_info *info)
 		ENABLE_DISABLE_DISPLAY(fb, enable);
 		break;
 	}
-	
+
 	SETUP_FB(fb);
 	return 0;
 }
@@ -1092,15 +1092,15 @@ stifb_init_display(struct stifb_info *fb)
 
 	/* HCRX specific initialization */
 	SETUP_HCRX(fb);
-	
+
 	/*
 	if (id == S9000_ID_HCRX)
 		hyperInitSprite(fb);
 	else
 		ngleInitSprite(fb);
 	*/
-	
-	/* Initialize the image planes. */ 
+
+	/* Initialize the image planes. */
         switch (id) {
 	 case S9000_ID_HCRX:
 	    hyperResetPlanes(fb, ENABLE);
@@ -1170,7 +1170,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	fb = kzalloc(sizeof(*fb), GFP_ATOMIC);
 	if (!fb)
 		return -ENOMEM;
-	
+
 	info = &fb->info;
 
 	/* set struct to a known state */
@@ -1211,7 +1211,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 			dev_name, fb->id);
 		goto out_err0;
 	}
-	
+
 	/* default to 8 bpp on most graphic chips */
 	bpp = 8;
 	xres = sti_onscreen_x(fb->sti);
@@ -1232,7 +1232,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 		fb->id = S9000_ID_A1659A;
 		break;
 	case S9000_ID_TIMBER:	/* HP9000/710 Any (may be a grayscale device) */
-		if (strstr(dev_name, "GRAYSCALE") || 
+		if (strstr(dev_name, "GRAYSCALE") ||
 		    strstr(dev_name, "Grayscale") ||
 		    strstr(dev_name, "grayscale"))
 			var->grayscale = 1;
@@ -1271,16 +1271,16 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	case CRT_ID_VISUALIZE_EG:
 	case S9000_ID_ARTIST:	/* Artist */
 		break;
-	default: 
+	default:
 #ifdef FALLBACK_TO_1BPP
-	       	printk(KERN_WARNING 
+	       	printk(KERN_WARNING
 			"stifb: Unsupported graphics card (id=0x%08x) "
 				"- now trying 1bpp mode instead\n",
 			fb->id);
 		bpp = 1;	/* default to 1 bpp */
 		break;
 #else
-	       	printk(KERN_WARNING 
+	       	printk(KERN_WARNING
 			"stifb: Unsupported graphics card (id=0x%08x) "
 				"- skipping.\n",
 			fb->id);
@@ -1296,11 +1296,11 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	fix->line_length = (fb->sti->glob_cfg->total_x * bpp) / 8;
 	if (!fix->line_length)
 		fix->line_length = 2048; /* default */
-	
+
 	/* limit fbsize to max visible screen size */
 	if (fix->smem_len > yres*fix->line_length)
 		fix->smem_len = ALIGN(yres*fix->line_length, 4*1024*1024);
-	
+
 	fix->accel = FB_ACCEL_NONE;
 
 	switch (bpp) {
@@ -1326,7 +1326,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 	    default:
 		break;
 	}
-	
+
 	var->xres = var->xres_virtual = xres;
 	var->yres = var->yres_virtual = yres;
 	var->bits_per_pixel = bpp;
@@ -1352,7 +1352,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 				fix->smem_start, fix->smem_start+fix->smem_len);
 		goto out_err2;
 	}
-		
+
 	if (!request_mem_region(fix->mmio_start, fix->mmio_len, "stifb mmio")) {
 		printk(KERN_ERR "stifb: cannot reserve sti mmio region 0x%04lx-0x%04lx\n",
 				fix->mmio_start, fix->mmio_start+fix->mmio_len);
@@ -1366,11 +1366,11 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 
 	fb_info(&fb->info, "%s %dx%d-%d frame buffer device, %s, id: %04x, mmio: 0x%04lx\n",
 		fix->id,
-		var->xres, 
+		var->xres,
 		var->yres,
 		var->bits_per_pixel,
 		dev_name,
-		fb->id, 
+		fb->id,
 		fix->mmio_start);
 
 	return 0;
@@ -1399,7 +1399,7 @@ static int __init stifb_init(void)
 	struct sti_struct *sti;
 	struct sti_struct *def_sti;
 	int i;
-	
+
 #ifndef MODULE
 	char *option = NULL;
 
@@ -1411,7 +1411,7 @@ static int __init stifb_init(void)
 		printk(KERN_INFO "stifb: disabled by \"stifb=off\" kernel parameter\n");
 		return -ENXIO;
 	}
-	
+
 	def_sti = sti_get_rom(0);
 	if (def_sti) {
 		for (i = 1; i <= MAX_STI_ROMS; i++) {
@@ -1445,7 +1445,7 @@ stifb_cleanup(void)
 {
 	struct sti_struct *sti;
 	int i;
-	
+
 	for (i = 1; i <= MAX_STI_ROMS; i++) {
 		sti = sti_get_rom(i);
 		if (!sti)
@@ -1468,10 +1468,10 @@ int __init
 stifb_setup(char *options)
 {
 	int i;
-	
+
 	if (!options || !*options)
 		return 1;
-	
+
 	if (strncmp(options, "off", 3) == 0) {
 		stifb_disabled = 1;
 		options += 3;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 79/99] fbdev/sti: Constify option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Constify the intenal option string that is passed around among
functions. The caller owns the memory and callees do not modify
its content. This change will later allow to constify the caller's
option string as well. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/stifb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index a151377f5b45..304ce8fcb9f8 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -1392,7 +1392,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 static int stifb_disabled __initdata;
 
 int __init
-stifb_setup(char *options);
+stifb_setup(const char *options);
 
 static int __init stifb_init(void)
 {
@@ -1465,7 +1465,7 @@ stifb_cleanup(void)
 }
 
 int __init
-stifb_setup(char *options)
+stifb_setup(const char *options)
 {
 	int i;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 79/99] fbdev/sti: Constify option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Constify the intenal option string that is passed around among
functions. The caller owns the memory and callees do not modify
its content. This change will later allow to constify the caller's
option string as well. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/stifb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index a151377f5b45..304ce8fcb9f8 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -1392,7 +1392,7 @@ static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
 static int stifb_disabled __initdata;
 
 int __init
-stifb_setup(char *options);
+stifb_setup(const char *options);
 
 static int __init stifb_init(void)
 {
@@ -1465,7 +1465,7 @@ stifb_cleanup(void)
 }
 
 int __init
-stifb_setup(char *options)
+stifb_setup(const char *options)
 {
 	int i;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 80/99] fbdev/tdfxfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tdfxfb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index d17e5e1472aa..ed3d8491e724 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -1589,7 +1589,15 @@ static void __init tdfxfb_setup(char *options)
 		} else if (!strncmp(this_opt, "nomtrr", 6)) {
 			nomtrr = 1;
 		} else {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "tdfxfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "tdfxfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		}
 	}
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 80/99] fbdev/tdfxfb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tdfxfb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index d17e5e1472aa..ed3d8491e724 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -1589,7 +1589,15 @@ static void __init tdfxfb_setup(char *options)
 		} else if (!strncmp(this_opt, "nomtrr", 6)) {
 			nomtrr = 1;
 		} else {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "tdfxfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "tdfxfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		}
 	}
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 81/99] fbdev/tdfxfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tdfxfb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index ed3d8491e724..54b19ce40bff 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -65,6 +65,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1570,16 +1571,14 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 }
 
 #ifndef MODULE
-static void __init tdfxfb_setup(char *options)
+static void __init tdfxfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "nopan")) {
 			nopan = 1;
 		} else if (!strcmp(this_opt, "nowrap")) {
@@ -1600,6 +1599,8 @@ static void __init tdfxfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
 }
 #endif
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 81/99] fbdev/tdfxfb: Parse option string with struct option_iter
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tdfxfb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index ed3d8491e724..54b19ce40bff 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -65,6 +65,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -1570,16 +1571,14 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 }
 
 #ifndef MODULE
-static void __init tdfxfb_setup(char *options)
+static void __init tdfxfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "nopan")) {
 			nopan = 1;
 		} else if (!strcmp(this_opt, "nowrap")) {
@@ -1600,6 +1599,8 @@ static void __init tdfxfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
 }
 #endif
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 82/99] fbdev/tgafb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 15:59   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tgafb.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index 14d37c49633c..a412fdddfd8c 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -1579,9 +1579,21 @@ static int tgafb_setup(char *arg)
 		while ((this_opt = strsep(&arg, ","))) {
 			if (!*this_opt)
 				continue;
-			if (!strncmp(this_opt, "mode:", 5))
-				mode_option = this_opt+5;
-			else
+			if (!strncmp(this_opt, "mode:", 5)) {
+				static char mode_option_buf[256];
+				int ret;
+
+				ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s",
+					       this_opt + 5);
+				if (WARN(ret < 0,
+					 "tgafb: ignoring invalid option, ret=%d\n",
+					 ret))
+					continue;
+				if (WARN(ret >= sizeof(mode_option_buf),
+					 "tgafb: option too long\n"))
+					continue;
+				mode_option = mode_option_buf;
+			} else
 				printk(KERN_ERR
 				       "tgafb: unknown parameter %s\n",
 				       this_opt);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 82/99] fbdev/tgafb: Duplicate video-mode option string
@ 2023-03-06 15:59   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 15:59 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tgafb.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index 14d37c49633c..a412fdddfd8c 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -1579,9 +1579,21 @@ static int tgafb_setup(char *arg)
 		while ((this_opt = strsep(&arg, ","))) {
 			if (!*this_opt)
 				continue;
-			if (!strncmp(this_opt, "mode:", 5))
-				mode_option = this_opt+5;
-			else
+			if (!strncmp(this_opt, "mode:", 5)) {
+				static char mode_option_buf[256];
+				int ret;
+
+				ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s",
+					       this_opt + 5);
+				if (WARN(ret < 0,
+					 "tgafb: ignoring invalid option, ret=%d\n",
+					 ret))
+					continue;
+				if (WARN(ret >= sizeof(mode_option_buf),
+					 "tgafb: option too long\n"))
+					continue;
+				mode_option = mode_option_buf;
+			} else
 				printk(KERN_ERR
 				       "tgafb: unknown parameter %s\n",
 				       this_opt);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 83/99] fbdev/tgafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tgafb.c | 45 +++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index a412fdddfd8c..704909edf89d 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -14,6 +14,7 @@
 
 #include <linux/aperture.h>
 #include <linux/bitrev.h>
+#include <linux/cmdline.h>
 #include <linux/compiler.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -1571,35 +1572,31 @@ static void tgafb_exit(void)
 }
 
 #ifndef MODULE
-static int tgafb_setup(char *arg)
+static int tgafb_setup(const char *arg)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (arg && *arg) {
-		while ((this_opt = strsep(&arg, ","))) {
-			if (!*this_opt)
+	option_iter_init(&iter, arg);
+
+	while (option_iter_next(&iter, this_opt)) {
+		if (!strncmp(this_opt, "mode:", 5)) {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s",
+				       this_opt + 5);
+			if (WARN(ret < 0, "tgafb: ignoring invalid option, ret=%d\n", ret))
 				continue;
-			if (!strncmp(this_opt, "mode:", 5)) {
-				static char mode_option_buf[256];
-				int ret;
-
-				ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s",
-					       this_opt + 5);
-				if (WARN(ret < 0,
-					 "tgafb: ignoring invalid option, ret=%d\n",
-					 ret))
-					continue;
-				if (WARN(ret >= sizeof(mode_option_buf),
-					 "tgafb: option too long\n"))
-					continue;
-				mode_option = mode_option_buf;
-			} else
-				printk(KERN_ERR
-				       "tgafb: unknown parameter %s\n",
-				       this_opt);
-		}
+			if (WARN(ret >= sizeof(mode_option_buf), "tgafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		} else
+			printk(KERN_ERR "tgafb: unknown parameter %s\n", this_opt);
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif /* !MODULE */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 83/99] fbdev/tgafb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tgafb.c | 45 +++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index a412fdddfd8c..704909edf89d 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -14,6 +14,7 @@
 
 #include <linux/aperture.h>
 #include <linux/bitrev.h>
+#include <linux/cmdline.h>
 #include <linux/compiler.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -1571,35 +1572,31 @@ static void tgafb_exit(void)
 }
 
 #ifndef MODULE
-static int tgafb_setup(char *arg)
+static int tgafb_setup(const char *arg)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (arg && *arg) {
-		while ((this_opt = strsep(&arg, ","))) {
-			if (!*this_opt)
+	option_iter_init(&iter, arg);
+
+	while (option_iter_next(&iter, this_opt)) {
+		if (!strncmp(this_opt, "mode:", 5)) {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s",
+				       this_opt + 5);
+			if (WARN(ret < 0, "tgafb: ignoring invalid option, ret=%d\n", ret))
 				continue;
-			if (!strncmp(this_opt, "mode:", 5)) {
-				static char mode_option_buf[256];
-				int ret;
-
-				ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s",
-					       this_opt + 5);
-				if (WARN(ret < 0,
-					 "tgafb: ignoring invalid option, ret=%d\n",
-					 ret))
-					continue;
-				if (WARN(ret >= sizeof(mode_option_buf),
-					 "tgafb: option too long\n"))
-					continue;
-				mode_option = mode_option_buf;
-			} else
-				printk(KERN_ERR
-				       "tgafb: unknown parameter %s\n",
-				       this_opt);
-		}
+			if (WARN(ret >= sizeof(mode_option_buf), "tgafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		} else
+			printk(KERN_ERR "tgafb: unknown parameter %s\n", this_opt);
 	}
 
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif /* !MODULE */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 84/99] fbdev/tmiofb: Remove unused option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

The option string is unused. Remove the variable and a related
helper function. No functional change.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tmiofb.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/video/fbdev/tmiofb.c b/drivers/video/fbdev/tmiofb.c
index 50111966c981..8920cee52d7f 100644
--- a/drivers/video/fbdev/tmiofb.c
+++ b/drivers/video/fbdev/tmiofb.c
@@ -11,6 +11,7 @@
  *	code written by Sharp/Lineo for 2.4 kernels
  */
 
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -997,32 +998,11 @@ static struct platform_driver tmiofb_driver = {
 
 /*--------------------------------------------------------------------------*/
 
-#ifndef MODULE
-static void __init tmiofb_setup(char *options)
-{
-	char *this_opt;
-
-	if (!options || !*options)
-		return;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
-		/*
-		 * FIXME
-		 */
-	}
-}
-#endif
-
 static int __init tmiofb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
-
-	if (fb_get_options("tmiofb", &option))
+	if (fb_get_options("tmiofb", NULL))
 		return -ENODEV;
-	tmiofb_setup(option);
 #endif
 	return platform_driver_register(&tmiofb_driver);
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 84/99] fbdev/tmiofb: Remove unused option string
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

The option string is unused. Remove the variable and a related
helper function. No functional change.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tmiofb.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/video/fbdev/tmiofb.c b/drivers/video/fbdev/tmiofb.c
index 50111966c981..8920cee52d7f 100644
--- a/drivers/video/fbdev/tmiofb.c
+++ b/drivers/video/fbdev/tmiofb.c
@@ -11,6 +11,7 @@
  *	code written by Sharp/Lineo for 2.4 kernels
  */
 
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -997,32 +998,11 @@ static struct platform_driver tmiofb_driver = {
 
 /*--------------------------------------------------------------------------*/
 
-#ifndef MODULE
-static void __init tmiofb_setup(char *options)
-{
-	char *this_opt;
-
-	if (!options || !*options)
-		return;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
-		/*
-		 * FIXME
-		 */
-	}
-}
-#endif
-
 static int __init tmiofb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
-
-	if (fb_get_options("tmiofb", &option))
+	if (fb_get_options("tmiofb", NULL))
 		return -ENODEV;
-	tmiofb_setup(option);
 #endif
 	return platform_driver_register(&tmiofb_driver);
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 85/99] fbdev/tridentfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tridentfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 6099b9768ba1..21cee678047b 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -1800,8 +1800,17 @@ static int __init tridentfb_setup(char *options)
 			memdiff = simple_strtoul(opt + 8, NULL, 0);
 		else if (!strncmp(opt, "nativex=", 8))
 			nativex = simple_strtoul(opt + 8, NULL, 0);
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "tridentfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "tridentfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 85/99] fbdev/tridentfb: Duplicate video-mode option string
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tridentfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 6099b9768ba1..21cee678047b 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -1800,8 +1800,17 @@ static int __init tridentfb_setup(char *options)
 			memdiff = simple_strtoul(opt + 8, NULL, 0);
 		else if (!strncmp(opt, "nativex=", 8))
 			nativex = simple_strtoul(opt + 8, NULL, 0);
-		else
-			mode_option = opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
+			if (WARN(ret < 0, "tridentfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "tridentfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 86/99] fbdev/tridentfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tridentfb.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 21cee678047b..0b8d4bc514e2 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -17,6 +17,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/fb.h>
 #include <linux/init.h>
@@ -1774,14 +1775,14 @@ static struct pci_driver tridentfb_pci_driver = {
  *	video=trident:800x600,bpp=16,noaccel
  */
 #ifndef MODULE
-static int __init tridentfb_setup(char *options)
+static int __init tridentfb_setup(const char *options)
 {
-	char *opt;
-	if (!options || !*options)
-		return 0;
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	struct option_iter iter;
+	const char *opt;
+
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, opt)) {
 		if (!strncmp(opt, "noaccel", 7))
 			noaccel = 1;
 		else if (!strncmp(opt, "fp", 2))
@@ -1812,6 +1813,9 @@ static int __init tridentfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 86/99] fbdev/tridentfb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/tridentfb.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 21cee678047b..0b8d4bc514e2 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -17,6 +17,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/fb.h>
 #include <linux/init.h>
@@ -1774,14 +1775,14 @@ static struct pci_driver tridentfb_pci_driver = {
  *	video=trident:800x600,bpp=16,noaccel
  */
 #ifndef MODULE
-static int __init tridentfb_setup(char *options)
+static int __init tridentfb_setup(const char *options)
 {
-	char *opt;
-	if (!options || !*options)
-		return 0;
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
-			continue;
+	struct option_iter iter;
+	const char *opt;
+
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, opt)) {
 		if (!strncmp(opt, "noaccel", 7))
 			noaccel = 1;
 		else if (!strncmp(opt, "fp", 2))
@@ -1812,6 +1813,9 @@ static int __init tridentfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 87/99] fbdev/uvesafb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/uvesafb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
index f09f483c219b..201f6bba0763 100644
--- a/drivers/video/fbdev/uvesafb.c
+++ b/drivers/video/fbdev/uvesafb.c
@@ -1851,7 +1851,15 @@ static int uvesafb_setup(char *options)
 		else if (!strncmp(this_opt, "vbemode:", 8))
 			vbemode = simple_strtoul(this_opt + 8, NULL, 0);
 		else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "uvesafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "uvesafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		} else {
 			pr_warn("unrecognized option %s\n", this_opt);
 		}
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 87/99] fbdev/uvesafb: Duplicate video-mode option string
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/uvesafb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
index f09f483c219b..201f6bba0763 100644
--- a/drivers/video/fbdev/uvesafb.c
+++ b/drivers/video/fbdev/uvesafb.c
@@ -1851,7 +1851,15 @@ static int uvesafb_setup(char *options)
 		else if (!strncmp(this_opt, "vbemode:", 8))
 			vbemode = simple_strtoul(this_opt + 8, NULL, 0);
 		else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
-			mode_option = this_opt;
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "uvesafb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "uvesafb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
 		} else {
 			pr_warn("unrecognized option %s\n", this_opt);
 		}
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 88/99] fbdev/uvesafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/uvesafb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
index 201f6bba0763..aada6a44380c 100644
--- a/drivers/video/fbdev/uvesafb.c
+++ b/drivers/video/fbdev/uvesafb.c
@@ -9,6 +9,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/cmdline.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
@@ -1808,16 +1809,14 @@ static struct platform_driver uvesafb_driver = {
 static struct platform_device *uvesafb_device;
 
 #ifndef MODULE
-static int uvesafb_setup(char *options)
+static int uvesafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "redraw"))
 			ypan = 0;
 		else if (!strcmp(this_opt, "ypan"))
@@ -1865,6 +1864,8 @@ static int uvesafb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	if (mtrr != 3 && mtrr != 0)
 		pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr);
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 88/99] fbdev/uvesafb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/uvesafb.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
index 201f6bba0763..aada6a44380c 100644
--- a/drivers/video/fbdev/uvesafb.c
+++ b/drivers/video/fbdev/uvesafb.c
@@ -9,6 +9,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/cmdline.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
@@ -1808,16 +1809,14 @@ static struct platform_driver uvesafb_driver = {
 static struct platform_device *uvesafb_device;
 
 #ifndef MODULE
-static int uvesafb_setup(char *options)
+static int uvesafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strcmp(this_opt, "redraw"))
 			ypan = 0;
 		else if (!strcmp(this_opt, "ypan"))
@@ -1865,6 +1864,8 @@ static int uvesafb_setup(char *options)
 		}
 	}
 
+	option_iter_release(&iter);
+
 	if (mtrr != 3 && mtrr != 0)
 		pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr);
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 89/99] fbdev/valkyriefb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/valkyriefb.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index 1007023a5e88..b166b7cfe0e5 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -1,7 +1,7 @@
 /*
  *  valkyriefb.c -- frame buffer device for the PowerMac 'valkyrie' display
  *
- *  Created 8 August 1998 by 
+ *  Created 8 August 1998 by
  *  Martin Costabel <costabel@wanadoo.fr> and Kevin Schoedel
  *
  *  Vmode-switching changes and vmode 15/17 modifications created 29 August
@@ -77,13 +77,13 @@ struct fb_info_valkyrie {
 	struct fb_par_valkyrie	par;
 	struct cmap_regs	__iomem *cmap_regs;
 	unsigned long		cmap_regs_phys;
-	
+
 	struct valkyrie_regs	__iomem *valkyrie_regs;
 	unsigned long		valkyrie_regs_phys;
-	
+
 	__u8			__iomem *frame_buffer;
 	unsigned long		frame_buffer_phys;
-	
+
 	int			sense;
 	unsigned long		total_vram;
 
@@ -244,7 +244,7 @@ static inline int valkyrie_vram_reqd(int video_mode, int color_mode)
 {
 	int pitch;
 	struct valkyrie_regvals *init = valkyrie_reg_init[video_mode-1];
-	
+
 	if ((pitch = init->pitch[color_mode]) == 0)
 		pitch = 2 * init->pitch[0];
 	return init->vres * pitch;
@@ -467,7 +467,7 @@ static int valkyrie_var_to_par(struct fb_var_screeninfo *var,
 		printk(KERN_ERR "valkyriefb: vmode %d not valid.\n", vmode);
 		return -EINVAL;
 	}
-	
+
 	if (cmode != CMODE_8 && cmode != CMODE_16) {
 		printk(KERN_ERR "valkyriefb: cmode %d not valid.\n", cmode);
 		return -EINVAL;
@@ -516,7 +516,7 @@ static void valkyrie_init_fix(struct fb_fix_screeninfo *fix, struct fb_info_valk
 	fix->ywrapstep = 0;
 	fix->ypanstep = 0;
 	fix->xpanstep = 0;
-	
+
 }
 
 /* Fix must already be inited above */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 89/99] fbdev/valkyriefb: Remove trailing whitespaces
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/valkyriefb.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index 1007023a5e88..b166b7cfe0e5 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -1,7 +1,7 @@
 /*
  *  valkyriefb.c -- frame buffer device for the PowerMac 'valkyrie' display
  *
- *  Created 8 August 1998 by 
+ *  Created 8 August 1998 by
  *  Martin Costabel <costabel@wanadoo.fr> and Kevin Schoedel
  *
  *  Vmode-switching changes and vmode 15/17 modifications created 29 August
@@ -77,13 +77,13 @@ struct fb_info_valkyrie {
 	struct fb_par_valkyrie	par;
 	struct cmap_regs	__iomem *cmap_regs;
 	unsigned long		cmap_regs_phys;
-	
+
 	struct valkyrie_regs	__iomem *valkyrie_regs;
 	unsigned long		valkyrie_regs_phys;
-	
+
 	__u8			__iomem *frame_buffer;
 	unsigned long		frame_buffer_phys;
-	
+
 	int			sense;
 	unsigned long		total_vram;
 
@@ -244,7 +244,7 @@ static inline int valkyrie_vram_reqd(int video_mode, int color_mode)
 {
 	int pitch;
 	struct valkyrie_regvals *init = valkyrie_reg_init[video_mode-1];
-	
+
 	if ((pitch = init->pitch[color_mode]) == 0)
 		pitch = 2 * init->pitch[0];
 	return init->vres * pitch;
@@ -467,7 +467,7 @@ static int valkyrie_var_to_par(struct fb_var_screeninfo *var,
 		printk(KERN_ERR "valkyriefb: vmode %d not valid.\n", vmode);
 		return -EINVAL;
 	}
-	
+
 	if (cmode != CMODE_8 && cmode != CMODE_16) {
 		printk(KERN_ERR "valkyriefb: cmode %d not valid.\n", cmode);
 		return -EINVAL;
@@ -516,7 +516,7 @@ static void valkyrie_init_fix(struct fb_fix_screeninfo *fix, struct fb_info_valk
 	fix->ywrapstep = 0;
 	fix->ypanstep = 0;
 	fix->xpanstep = 0;
-	
+
 }
 
 /* Fix must already be inited above */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 90/99] fbdev/valkyriefb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/valkyriefb.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index b166b7cfe0e5..a787b0142d00 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -39,6 +39,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -90,7 +91,7 @@ struct fb_info_valkyrie {
 	u32			pseudo_palette[16];
 };
 
-static int valkyriefb_setup(char*);
+static int valkyriefb_setup(const char *options);
 
 static int valkyriefb_check_var(struct fb_var_screeninfo *var,
 				struct fb_info *info);
@@ -545,14 +546,14 @@ static int __init valkyrie_init_info(struct fb_info *info,
 /*
  * Parse user specified options (`video=valkyriefb:')
  */
-static int __init valkyriefb_setup(char *options)
+static int __init valkyriefb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "vmode:", 6)) {
 	    		int vmode = simple_strtoul(this_opt+6, NULL, 0);
 			if (vmode > 0 && vmode <= VMODE_MAX)
@@ -571,6 +572,9 @@ static int __init valkyriefb_setup(char *options)
 			}
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 90/99] fbdev/valkyriefb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/valkyriefb.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index b166b7cfe0e5..a787b0142d00 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -39,6 +39,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -90,7 +91,7 @@ struct fb_info_valkyrie {
 	u32			pseudo_palette[16];
 };
 
-static int valkyriefb_setup(char*);
+static int valkyriefb_setup(const char *options);
 
 static int valkyriefb_check_var(struct fb_var_screeninfo *var,
 				struct fb_info *info);
@@ -545,14 +546,14 @@ static int __init valkyrie_init_info(struct fb_info *info,
 /*
  * Parse user specified options (`video=valkyriefb:')
  */
-static int __init valkyriefb_setup(char *options)
+static int __init valkyriefb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "vmode:", 6)) {
 	    		int vmode = simple_strtoul(this_opt+6, NULL, 0);
 			if (vmode > 0 && vmode <= VMODE_MAX)
@@ -571,6 +572,9 @@ static int __init valkyriefb_setup(char *options)
 			}
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 91/99] fbdev/vermilion: Remove unused option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

The option string is unused. Remove the variable. No functional
changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vermilion/vermilion.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/vermilion/vermilion.c b/drivers/video/fbdev/vermilion/vermilion.c
index 0374ee6b6d03..bea318504475 100644
--- a/drivers/video/fbdev/vermilion/vermilion.c
+++ b/drivers/video/fbdev/vermilion/vermilion.c
@@ -1056,16 +1056,11 @@ static void __exit vmlfb_cleanup(void)
 
 static int __init vmlfb_init(void)
 {
-
-#ifndef MODULE
-	char *option = NULL;
-#endif
-
 	if (fb_modesetting_disabled("vmlfb"))
 		return -ENODEV;
 
 #ifndef MODULE
-	if (fb_get_options(MODULE_NAME, &option))
+	if (fb_get_options(MODULE_NAME, NULL))
 		return -ENODEV;
 #endif
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 91/99] fbdev/vermilion: Remove unused option string
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

The option string is unused. Remove the variable. No functional
changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vermilion/vermilion.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/vermilion/vermilion.c b/drivers/video/fbdev/vermilion/vermilion.c
index 0374ee6b6d03..bea318504475 100644
--- a/drivers/video/fbdev/vermilion/vermilion.c
+++ b/drivers/video/fbdev/vermilion/vermilion.c
@@ -1056,16 +1056,11 @@ static void __exit vmlfb_cleanup(void)
 
 static int __init vmlfb_init(void)
 {
-
-#ifndef MODULE
-	char *option = NULL;
-#endif
-
 	if (fb_modesetting_disabled("vmlfb"))
 		return -ENODEV;
 
 #ifndef MODULE
-	if (fb_get_options(MODULE_NAME, &option))
+	if (fb_get_options(MODULE_NAME, NULL))
 		return -ENODEV;
 #endif
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 92/99] fbdev/vesafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vesafb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 3f8bdfcf51f0..0310a3db2b10 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -209,16 +210,14 @@ static struct fb_ops vesafb_ops = {
 	.fb_imageblit	= cfb_imageblit,
 };
 
-static int vesafb_setup(char *options)
+static int vesafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (! strcmp(this_opt, "inverse"))
 			inverse=1;
 		else if (! strcmp(this_opt, "redraw"))
@@ -240,6 +239,9 @@ static int vesafb_setup(char *options)
 		else if (! strncmp(this_opt, "vremap:", 7))
 			vram_remap = simple_strtoul(this_opt+7, NULL, 0);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 92/99] fbdev/vesafb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vesafb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 3f8bdfcf51f0..0310a3db2b10 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -209,16 +210,14 @@ static struct fb_ops vesafb_ops = {
 	.fb_imageblit	= cfb_imageblit,
 };
 
-static int vesafb_setup(char *options)
+static int vesafb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt) continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (! strcmp(this_opt, "inverse"))
 			inverse=1;
 		else if (! strcmp(this_opt, "redraw"))
@@ -240,6 +239,9 @@ static int vesafb_setup(char *options)
 		else if (! strncmp(this_opt, "vremap:", 7))
 			vram_remap = simple_strtoul(this_opt+7, NULL, 0);
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 93/99] fbdev/vfb: Remove trailing whitespaces
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vfb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index 95d3c59867d0..680c88267ef4 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -110,7 +110,7 @@ static u_long get_line_length(int xres_virtual, int bpp)
      *  First part, xxxfb_check_var, must not write anything
      *  to hardware, it should only verify and adjust var.
      *  This means it doesn't alter par but it does use hardware
-     *  data from it to check this var. 
+     *  data from it to check this var.
      */
 
 static int vfb_check_var(struct fb_var_screeninfo *var,
@@ -168,7 +168,7 @@ static int vfb_check_var(struct fb_var_screeninfo *var,
 
 	/*
 	 * Now that we checked it we alter var. The reason being is that the video
-	 * mode passed in might not work but slight changes to it might make it 
+	 * mode passed in might not work but slight changes to it might make it
 	 * work. This way we let the user know what is acceptable.
 	 */
 	switch (var->bits_per_pixel) {
@@ -234,8 +234,8 @@ static int vfb_check_var(struct fb_var_screeninfo *var,
 }
 
 /* This routine actually sets the video mode. It's in here where we
- * the hardware state info->par and fix which can be affected by the 
- * change in par. For this driver it doesn't do much. 
+ * the hardware state info->par and fix which can be affected by the
+ * change in par. For this driver it doesn't do much.
  */
 static int vfb_set_par(struct fb_info *info)
 {
@@ -378,7 +378,7 @@ static int vfb_pan_display(struct fb_var_screeninfo *var,
 }
 
     /*
-     *  Most drivers don't need their own mmap function 
+     *  Most drivers don't need their own mmap function
      */
 
 static int vfb_mmap(struct fb_info *info,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 93/99] fbdev/vfb: Remove trailing whitespaces
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vfb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index 95d3c59867d0..680c88267ef4 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -110,7 +110,7 @@ static u_long get_line_length(int xres_virtual, int bpp)
      *  First part, xxxfb_check_var, must not write anything
      *  to hardware, it should only verify and adjust var.
      *  This means it doesn't alter par but it does use hardware
-     *  data from it to check this var. 
+     *  data from it to check this var.
      */
 
 static int vfb_check_var(struct fb_var_screeninfo *var,
@@ -168,7 +168,7 @@ static int vfb_check_var(struct fb_var_screeninfo *var,
 
 	/*
 	 * Now that we checked it we alter var. The reason being is that the video
-	 * mode passed in might not work but slight changes to it might make it 
+	 * mode passed in might not work but slight changes to it might make it
 	 * work. This way we let the user know what is acceptable.
 	 */
 	switch (var->bits_per_pixel) {
@@ -234,8 +234,8 @@ static int vfb_check_var(struct fb_var_screeninfo *var,
 }
 
 /* This routine actually sets the video mode. It's in here where we
- * the hardware state info->par and fix which can be affected by the 
- * change in par. For this driver it doesn't do much. 
+ * the hardware state info->par and fix which can be affected by the
+ * change in par. For this driver it doesn't do much.
  */
 static int vfb_set_par(struct fb_info *info)
 {
@@ -378,7 +378,7 @@ static int vfb_pan_display(struct fb_var_screeninfo *var,
 }
 
     /*
-     *  Most drivers don't need their own mmap function 
+     *  Most drivers don't need their own mmap function
      */
 
 static int vfb_mmap(struct fb_info *info,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 94/99] fbdev/vfb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index 680c88267ef4..15a6a0896ab5 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -412,8 +412,17 @@ static int __init vfb_setup(char *options)
 		/* Test disable for backwards compatibility */
 		if (!strcmp(this_opt, "disable"))
 			vfb_enable = 0;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "vfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "vfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 1;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 94/99] fbdev/vfb: Duplicate video-mode option string
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index 680c88267ef4..15a6a0896ab5 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -412,8 +412,17 @@ static int __init vfb_setup(char *options)
 		/* Test disable for backwards compatibility */
 		if (!strcmp(this_opt, "disable"))
 			vfb_enable = 0;
-		else
-			mode_option = this_opt;
+		else {
+			static char mode_option_buf[256];
+			int ret;
+
+			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
+			if (WARN(ret < 0, "vfb: ignoring invalid option, ret=%d\n", ret))
+				continue;
+			if (WARN(ret >= sizeof(mode_option_buf), "vfb: option too long\n"))
+				continue;
+			mode_option = mode_option_buf;
+		}
 	}
 	return 1;
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 95/99] fbdev/vfb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vfb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index 15a6a0896ab5..ef22a6815e70 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -10,6 +10,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -392,9 +393,10 @@ static int vfb_mmap(struct fb_info *info,
  * The virtual framebuffer driver is only enabled if explicitly
  * requested by passing 'video=vfb:' (or any actual options).
  */
-static int __init vfb_setup(char *options)
+static int __init vfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	vfb_enable = 0;
 
@@ -403,12 +405,9 @@ static int __init vfb_setup(char *options)
 
 	vfb_enable = 1;
 
-	if (!*options)
-		return 1;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		/* Test disable for backwards compatibility */
 		if (!strcmp(this_opt, "disable"))
 			vfb_enable = 0;
@@ -424,6 +423,9 @@ static int __init vfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 1;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 95/99] fbdev/vfb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vfb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index 15a6a0896ab5..ef22a6815e70 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -10,6 +10,7 @@
  *  more details.
  */
 
+#include <linux/cmdline.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -392,9 +393,10 @@ static int vfb_mmap(struct fb_info *info,
  * The virtual framebuffer driver is only enabled if explicitly
  * requested by passing 'video=vfb:' (or any actual options).
  */
-static int __init vfb_setup(char *options)
+static int __init vfb_setup(const char *options)
 {
-	char *this_opt;
+	struct option_iter iter;
+	const char *this_opt;
 
 	vfb_enable = 0;
 
@@ -403,12 +405,9 @@ static int __init vfb_setup(char *options)
 
 	vfb_enable = 1;
 
-	if (!*options)
-		return 1;
+	option_iter_init(&iter, options);
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	while (option_iter_next(&iter, this_opt)) {
 		/* Test disable for backwards compatibility */
 		if (!strcmp(this_opt, "disable"))
 			vfb_enable = 0;
@@ -424,6 +423,9 @@ static int __init vfb_setup(char *options)
 			mode_option = mode_option_buf;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 1;
 }
 #endif  /*  MODULE  */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 96/99] fbdev/viafb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/via/viafbdev.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 2d67c92c5774..4f39319e21f8 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -5,6 +5,7 @@
 
  */
 
+#include <linux/cmdline.h>
 #include <linux/compiler.h>
 #include <linux/module.h>
 #include <linux/seq_file.h>
@@ -1922,21 +1923,18 @@ void via_fb_pci_remove(struct pci_dev *pdev)
 #ifndef MODULE
 static int __init viafb_setup(void)
 {
-	char *this_opt;
 	char *options;
+	struct option_iter iter;
+	const char *this_opt;
 
 	DEBUG_MSG(KERN_INFO "viafb_setup!\n");
 
 	if (fb_get_options("viafb", &options))
 		return -ENODEV;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
 			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
 			if (!viafb_mode1)
@@ -2009,6 +2007,9 @@ static int __init viafb_setup(void)
 				return -ENOMEM;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 96/99] fbdev/viafb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/via/viafbdev.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 2d67c92c5774..4f39319e21f8 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -5,6 +5,7 @@
 
  */
 
+#include <linux/cmdline.h>
 #include <linux/compiler.h>
 #include <linux/module.h>
 #include <linux/seq_file.h>
@@ -1922,21 +1923,18 @@ void via_fb_pci_remove(struct pci_dev *pdev)
 #ifndef MODULE
 static int __init viafb_setup(void)
 {
-	char *this_opt;
 	char *options;
+	struct option_iter iter;
+	const char *this_opt;
 
 	DEBUG_MSG(KERN_INFO "viafb_setup!\n");
 
 	if (fb_get_options("viafb", &options))
 		return -ENODEV;
 
-	if (!options || !*options)
-		return 0;
-
-	while ((this_opt = strsep(&options, ",")) != NULL) {
-		if (!*this_opt)
-			continue;
+	option_iter_init(&iter, options);
 
+	while (option_iter_next(&iter, this_opt)) {
 		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
 			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
 			if (!viafb_mode1)
@@ -2009,6 +2007,9 @@ static int __init viafb_setup(void)
 				return -ENOMEM;
 		}
 	}
+
+	option_iter_release(&iter);
+
 	return 0;
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vt8623fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/vt8623fb.c b/drivers/video/fbdev/vt8623fb.c
index 034333ee6e45..cbdca42d1708 100644
--- a/drivers/video/fbdev/vt8623fb.c
+++ b/drivers/video/fbdev/vt8623fb.c
@@ -929,8 +929,17 @@ static int __init vt8623fb_init(void)
 	if (fb_get_options("vt8623fb", &option))
 		return -ENODEV;
 
-	if (option && *option)
-		mode_option = option;
+	if (option && *option) {
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
+		if (WARN(ret < 0, "vt8623fb: ignoring invalid option, ret=%d\n", ret))
+			break;
+		if (WARN(ret >= sizeof(mode_option_buf), "vt8623fb: option too long\n"))
+			break;
+		mode_option = mode_option_buf;
+	}
 #endif
 
 	pr_debug("vt8623fb: initializing\n");
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. The driver only
parses the option string once as part of module initialization, so use
a static buffer to store the duplicated mode option. Linux automatically
frees the memory upon releasing the module.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/vt8623fb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/vt8623fb.c b/drivers/video/fbdev/vt8623fb.c
index 034333ee6e45..cbdca42d1708 100644
--- a/drivers/video/fbdev/vt8623fb.c
+++ b/drivers/video/fbdev/vt8623fb.c
@@ -929,8 +929,17 @@ static int __init vt8623fb_init(void)
 	if (fb_get_options("vt8623fb", &option))
 		return -ENODEV;
 
-	if (option && *option)
-		mode_option = option;
+	if (option && *option) {
+		static char mode_option_buf[256];
+		int ret;
+
+		ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
+		if (WARN(ret < 0, "vt8623fb: ignoring invalid option, ret=%d\n", ret))
+			break;
+		if (WARN(ret >= sizeof(mode_option_buf), "vt8623fb: option too long\n"))
+			break;
+		mode_option = mode_option_buf;
+	}
 #endif
 
 	pr_debug("vt8623fb: initializing\n");
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 98/99] staging/sm750fb: Parse option string with struct option_iter
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/staging/sm750fb/sm750.c | 43 +++++++++++++++++----------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index effc7fcc3703..2eb223f0631e 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/errno.h>
@@ -867,9 +868,10 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
 }
 
 /*	chip specific g_option configuration routine */
-static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
+static void sm750fb_setup(struct sm750_dev *sm750_dev, const char *src)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 	int swap;
 
 	swap = 0;
@@ -889,9 +891,12 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
 		goto NO_PARAM;
 	}
 
-	while ((opt = strsep(&src, ":")) != NULL && *opt != 0) {
+	dev_info(&sm750_dev->pdev->dev, "src=%s\n", src);
+
+	option_iter_init(&iter, src);
+
+	while (option_iter_next(&iter, opt)) {
 		dev_info(&sm750_dev->pdev->dev, "opt=%s\n", opt);
-		dev_info(&sm750_dev->pdev->dev, "src=%s\n", src);
 
 		if (!strncmp(opt, "swap", strlen("swap"))) {
 			swap = 1;
@@ -924,6 +929,8 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
 		}
 	}
 
+	option_iter_release(&iter);
+
 NO_PARAM:
 	if (sm750_dev->revid != SM750LE_REVISION_ID) {
 		if (sm750_dev->fb_count > 1) {
@@ -1096,10 +1103,12 @@ static void lynxfb_pci_remove(struct pci_dev *pdev)
 	kfree(g_settings);
 }
 
-static int __init lynxfb_setup(char *options)
+static int __init lynxfb_setup(const char *options)
 {
+	struct option_iter iter;
+	const char *opt;
 	int len;
-	char *opt, *tmp;
+	char *tmp;
 
 	if (!options || !*options) {
 		pr_warn("no options.\n");
@@ -1112,19 +1121,11 @@ static int __init lynxfb_setup(char *options)
 	g_settings = kzalloc(len, GFP_KERNEL);
 	if (!g_settings)
 		return -ENOMEM;
-
 	tmp = g_settings;
 
-	/*
-	 * Notes:
-	 * char * strsep(char **s,const char * ct);
-	 * @s: the string to be searched
-	 * @ct :the characters to search for
-	 *
-	 * strsep() updates @options to pointer after the first found token
-	 * it also returns the pointer ahead the token.
-	 */
-	while ((opt = strsep(&options, ":")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, opt)) {
 		/* options that mean for any lynx chips are configured here */
 		if (!strncmp(opt, "noaccel", strlen("noaccel"))) {
 			g_noaccel = 1;
@@ -1133,15 +1134,15 @@ static int __init lynxfb_setup(char *options)
 		} else if (!strncmp(opt, "dual", strlen("dual"))) {
 			g_dualview = 1;
 		} else {
+			if (tmp != g_settings)
+				*tmp++ = ':'; // add separator
 			strcat(tmp, opt);
 			tmp += strlen(opt);
-			if (options)
-				*tmp++ = ':';
-			else
-				*tmp++ = 0;
 		}
 	}
 
+	option_iter_release(&iter);
+
 	/* misc g_settings are transport to chip specific routines */
 	pr_info("parameter left for chip specific analysis:%s\n", g_settings);
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 98/99] staging/sm750fb: Parse option string with struct option_iter
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.

Done in preparation of constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/staging/sm750fb/sm750.c | 43 +++++++++++++++++----------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index effc7fcc3703..2eb223f0631e 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/aperture.h>
+#include <linux/cmdline.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/errno.h>
@@ -867,9 +868,10 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
 }
 
 /*	chip specific g_option configuration routine */
-static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
+static void sm750fb_setup(struct sm750_dev *sm750_dev, const char *src)
 {
-	char *opt;
+	struct option_iter iter;
+	const char *opt;
 	int swap;
 
 	swap = 0;
@@ -889,9 +891,12 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
 		goto NO_PARAM;
 	}
 
-	while ((opt = strsep(&src, ":")) != NULL && *opt != 0) {
+	dev_info(&sm750_dev->pdev->dev, "src=%s\n", src);
+
+	option_iter_init(&iter, src);
+
+	while (option_iter_next(&iter, opt)) {
 		dev_info(&sm750_dev->pdev->dev, "opt=%s\n", opt);
-		dev_info(&sm750_dev->pdev->dev, "src=%s\n", src);
 
 		if (!strncmp(opt, "swap", strlen("swap"))) {
 			swap = 1;
@@ -924,6 +929,8 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
 		}
 	}
 
+	option_iter_release(&iter);
+
 NO_PARAM:
 	if (sm750_dev->revid != SM750LE_REVISION_ID) {
 		if (sm750_dev->fb_count > 1) {
@@ -1096,10 +1103,12 @@ static void lynxfb_pci_remove(struct pci_dev *pdev)
 	kfree(g_settings);
 }
 
-static int __init lynxfb_setup(char *options)
+static int __init lynxfb_setup(const char *options)
 {
+	struct option_iter iter;
+	const char *opt;
 	int len;
-	char *opt, *tmp;
+	char *tmp;
 
 	if (!options || !*options) {
 		pr_warn("no options.\n");
@@ -1112,19 +1121,11 @@ static int __init lynxfb_setup(char *options)
 	g_settings = kzalloc(len, GFP_KERNEL);
 	if (!g_settings)
 		return -ENOMEM;
-
 	tmp = g_settings;
 
-	/*
-	 * Notes:
-	 * char * strsep(char **s,const char * ct);
-	 * @s: the string to be searched
-	 * @ct :the characters to search for
-	 *
-	 * strsep() updates @options to pointer after the first found token
-	 * it also returns the pointer ahead the token.
-	 */
-	while ((opt = strsep(&options, ":")) != NULL) {
+	option_iter_init(&iter, options);
+
+	while (option_iter_next(&iter, opt)) {
 		/* options that mean for any lynx chips are configured here */
 		if (!strncmp(opt, "noaccel", strlen("noaccel"))) {
 			g_noaccel = 1;
@@ -1133,15 +1134,15 @@ static int __init lynxfb_setup(char *options)
 		} else if (!strncmp(opt, "dual", strlen("dual"))) {
 			g_dualview = 1;
 		} else {
+			if (tmp != g_settings)
+				*tmp++ = ':'; // add separator
 			strcat(tmp, opt);
 			tmp += strlen(opt);
-			if (options)
-				*tmp++ = ':';
-			else
-				*tmp++ = 0;
 		}
 	}
 
+	option_iter_release(&iter);
+
 	/* misc g_settings are transport to chip specific routines */
 	pr_info("parameter left for chip specific analysis:%s\n", g_settings);
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 99/99] fbdev: Constify option strings
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-06 16:00   ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Return the option string as const char* from fb_get_options() to
enforce fbdev's ownership of the memory region. Also avoids memory
allocation within fb_get_options().

Callers that have to modify the option string must create their own
copy. As most drivers use struct option_iter, this already happens
transparently in many cases.

Adapt all callers of fb_get_options().

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/staging/sm750fb/sm750.c              |  2 +-
 drivers/video/fbdev/acornfb.c                |  2 +-
 drivers/video/fbdev/amifb.c                  |  2 +-
 drivers/video/fbdev/arkfb.c                  |  2 +-
 drivers/video/fbdev/atafb.c                  |  2 +-
 drivers/video/fbdev/aty/aty128fb.c           |  2 +-
 drivers/video/fbdev/aty/atyfb_base.c         |  2 +-
 drivers/video/fbdev/aty/radeon_base.c        |  2 +-
 drivers/video/fbdev/au1100fb.c               |  2 +-
 drivers/video/fbdev/au1200fb.c               |  2 +-
 drivers/video/fbdev/cirrusfb.c               |  2 +-
 drivers/video/fbdev/controlfb.c              |  2 +-
 drivers/video/fbdev/core/fb_cmdline.c        | 13 +++----------
 drivers/video/fbdev/core/modedb.c            |  8 ++------
 drivers/video/fbdev/cyber2000fb.c            |  2 +-
 drivers/video/fbdev/efifb.c                  |  2 +-
 drivers/video/fbdev/ep93xx-fb.c              |  2 +-
 drivers/video/fbdev/fm2fb.c                  |  2 +-
 drivers/video/fbdev/fsl-diu-fb.c             |  2 +-
 drivers/video/fbdev/gbefb.c                  |  2 +-
 drivers/video/fbdev/geode/gx1fb_core.c       |  2 +-
 drivers/video/fbdev/geode/gxfb_core.c        |  2 +-
 drivers/video/fbdev/geode/lxfb_core.c        |  2 +-
 drivers/video/fbdev/grvga.c                  |  3 ++-
 drivers/video/fbdev/gxt4500.c                |  2 +-
 drivers/video/fbdev/hyperv_fb.c              |  2 +-
 drivers/video/fbdev/i740fb.c                 |  2 +-
 drivers/video/fbdev/i810/i810_main.c         |  2 +-
 drivers/video/fbdev/imsttfb.c                |  2 +-
 drivers/video/fbdev/imxfb.c                  |  2 +-
 drivers/video/fbdev/intelfb/intelfbdrv.c     |  2 +-
 drivers/video/fbdev/kyro/fbdev.c             |  2 +-
 drivers/video/fbdev/macfb.c                  |  2 +-
 drivers/video/fbdev/matrox/matroxfb_base.c   |  2 +-
 drivers/video/fbdev/mx3fb.c                  |  2 +-
 drivers/video/fbdev/neofb.c                  |  2 +-
 drivers/video/fbdev/nvidia/nvidia.c          |  2 +-
 drivers/video/fbdev/ocfb.c                   |  2 +-
 drivers/video/fbdev/omap/omapfb_main.c       |  2 +-
 drivers/video/fbdev/platinumfb.c             |  2 +-
 drivers/video/fbdev/pm2fb.c                  |  2 +-
 drivers/video/fbdev/pm3fb.c                  |  2 +-
 drivers/video/fbdev/ps3fb.c                  |  2 +-
 drivers/video/fbdev/pvr2fb.c                 |  2 +-
 drivers/video/fbdev/pxafb.c                  |  2 +-
 drivers/video/fbdev/riva/fbdev.c             |  2 +-
 drivers/video/fbdev/s3fb.c                   |  2 +-
 drivers/video/fbdev/savage/savagefb_driver.c |  2 +-
 drivers/video/fbdev/sis/sis_main.c           |  2 +-
 drivers/video/fbdev/skeletonfb.c             |  2 +-
 drivers/video/fbdev/sm712fb.c                |  2 +-
 drivers/video/fbdev/sstfb.c                  |  2 +-
 drivers/video/fbdev/stifb.c                  |  2 +-
 drivers/video/fbdev/tdfxfb.c                 |  2 +-
 drivers/video/fbdev/tgafb.c                  |  2 +-
 drivers/video/fbdev/tridentfb.c              |  2 +-
 drivers/video/fbdev/uvesafb.c                |  2 +-
 drivers/video/fbdev/valkyriefb.c             |  2 +-
 drivers/video/fbdev/vesafb.c                 |  2 +-
 drivers/video/fbdev/vfb.c                    |  2 +-
 drivers/video/fbdev/via/viafbdev.c           |  2 +-
 drivers/video/fbdev/vt8623fb.c               |  3 +--
 include/linux/fb.h                           |  2 +-
 63 files changed, 67 insertions(+), 78 deletions(-)

diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 2eb223f0631e..fe5c18e00ac8 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -1167,7 +1167,7 @@ static struct pci_driver lynxfb_driver = {
 
 static int __init lynxfb_init(void)
 {
-	char *option;
+	const char *option;
 
 	if (fb_modesetting_disabled("sm750fb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 1d6dec45615c..be4aafb23a5c 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -926,7 +926,7 @@ static int acornfb_probe(struct platform_device *dev)
 	unsigned long size;
 	u_int h_sync, v_sync;
 	int rc, i;
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("acornfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index b968cf2c5f06..ef8518fd4fdc 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -3546,7 +3546,7 @@ static int __init amifb_probe(struct platform_device *pdev)
 	u_int defmode;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("amifb", &option)) {
 		amifb_video_off();
diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index f83fcdaec7a0..5c39b872e52d 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -1186,7 +1186,7 @@ static int __init arkfb_init(void)
 {
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("arkfb"))
diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 82d5567f2ffb..a77794ad18a7 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -2999,7 +2999,7 @@ static int __init atafb_probe(struct platform_device *pdev)
 	int pad, detected_mode, error;
 	unsigned int defmode = 0;
 	unsigned long mem_req;
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("atafb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
index 4a200eabe80b..40b42dcd00bb 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -2514,7 +2514,7 @@ static int __maybe_unused aty128_pci_resume(struct device *dev)
 static int aty128fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("aty128fb"))
diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
index 1920ee5c9a2a..fe3742cf4eb8 100644
--- a/drivers/video/fbdev/aty/atyfb_base.c
+++ b/drivers/video/fbdev/aty/atyfb_base.c
@@ -3970,7 +3970,7 @@ static int __init atyfb_init(void)
 {
 	int err1 = 1, err2 = 1;
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("atyfb"))
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index 185cd98ad59d..1d19a4b664ab 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -2616,7 +2616,7 @@ static int __init radeonfb_setup (const char *options)
 static int __init radeonfb_init (void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("radeonfb"))
diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c
index 17dae92ac53f..6976b201a3aa 100644
--- a/drivers/video/fbdev/au1100fb.c
+++ b/drivers/video/fbdev/au1100fb.c
@@ -366,7 +366,7 @@ static const struct fb_ops au1100fb_ops =
 
 static int au1100fb_setup(struct au1100fb_device *fbdev)
 {
-	char *options;
+	const char *options;
 	struct option_iter iter;
 	const char *this_opt;
 	int num_panels = ARRAY_SIZE(known_lcd_panels);
diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c
index 31a3f6afd8aa..c39bf715abad 100644
--- a/drivers/video/fbdev/au1200fb.c
+++ b/drivers/video/fbdev/au1200fb.c
@@ -1578,7 +1578,7 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
 
 static int au1200fb_setup(struct au1200fb_platdata *pd)
 {
-	char *options = NULL;
+	const char *options = NULL;
 	struct option_iter iter;
 	const char *this_opt;
 	char *endptr;
diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index c6882bff3862..28526af217c2 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -2369,7 +2369,7 @@ static int __init cirrusfb_init(void)
 	int error = 0;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("cirrusfb"))
diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 3633e874ab2e..dc1d1c7ebeee 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -1004,7 +1004,7 @@ static int __init control_of_init(struct device_node *dp)
 static int __init control_init(void)
 {
 	struct device_node *dp;
-	char *option = NULL;
+	const char *option = NULL;
 	int ret = -ENXIO;
 
 	if (fb_get_options("controlfb", &option))
diff --git a/drivers/video/fbdev/core/fb_cmdline.c b/drivers/video/fbdev/core/fb_cmdline.c
index 4d1634c492ec..67f9df7096f1 100644
--- a/drivers/video/fbdev/core/fb_cmdline.c
+++ b/drivers/video/fbdev/core/fb_cmdline.c
@@ -28,12 +28,9 @@
  *          (video=<name>:<options>)
  * @option: the option will be stored here
  *
- * The caller owns the string returned in @option and is
- * responsible for releasing the memory.
- *
  * NOTE: Needed to maintain backwards compatibility
  */
-int fb_get_options(const char *name, char **option)
+int fb_get_options(const char *name, const char **option)
 {
 	const char *options = NULL;
 	bool is_of = false;
@@ -49,12 +46,8 @@ int fb_get_options(const char *name, char **option)
 			enabled = false;
 	}
 
-	if (option) {
-		if (options)
-			*option = kstrdup(options, GFP_KERNEL);
-		else
-			*option = NULL;
-	}
+	if (option)
+		*option = options;
 
 	return enabled ? 0 : 1; // 0 on success, 1 otherwise
 }
diff --git a/drivers/video/fbdev/core/modedb.c b/drivers/video/fbdev/core/modedb.c
index 23cf8eba785d..5ff5a56925cc 100644
--- a/drivers/video/fbdev/core/modedb.c
+++ b/drivers/video/fbdev/core/modedb.c
@@ -620,7 +620,6 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 		 const struct fb_videomode *default_mode,
 		 unsigned int default_bpp)
 {
-	char *mode_option_buf = NULL;
 	int i;
 
 	/* Set up defaults */
@@ -636,10 +635,8 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 		default_bpp = 8;
 
 	/* Did the user specify a video mode? */
-	if (!mode_option) {
-		fb_get_options(NULL, &mode_option_buf);
-		mode_option = mode_option_buf;
-	}
+	if (!mode_option)
+		fb_get_options(NULL, &mode_option);
 	if (mode_option) {
 		const char *name = mode_option;
 		unsigned int namelen = strlen(name);
@@ -718,7 +715,6 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 			res_specified = 1;
 		}
 done:
-		kfree(mode_option_buf);
 		if (cvt) {
 			struct fb_videomode cvt_mode;
 			int ret;
diff --git a/drivers/video/fbdev/cyber2000fb.c b/drivers/video/fbdev/cyber2000fb.c
index 939dde664b53..4c147d1500bc 100644
--- a/drivers/video/fbdev/cyber2000fb.c
+++ b/drivers/video/fbdev/cyber2000fb.c
@@ -1877,7 +1877,7 @@ static int __init cyber2000fb_init(void)
 	int ret = -1, err;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("CyberPro"))
diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 1ae7574aaa82..669b259b78ab 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -366,7 +366,7 @@ static int efifb_probe(struct platform_device *dev)
 	unsigned int size_vmode;
 	unsigned int size_remap;
 	unsigned int size_total;
-	char *option = NULL;
+	const char *option = NULL;
 	efi_memory_desc_t md;
 
 	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled)
diff --git a/drivers/video/fbdev/ep93xx-fb.c b/drivers/video/fbdev/ep93xx-fb.c
index 305f1587bd89..33a9aa2ecc3b 100644
--- a/drivers/video/fbdev/ep93xx-fb.c
+++ b/drivers/video/fbdev/ep93xx-fb.c
@@ -464,7 +464,7 @@ static int ep93xxfb_probe(struct platform_device *pdev)
 	struct fb_info *info;
 	struct ep93xx_fbi *fbi;
 	struct resource *res;
-	char *video_mode;
+	const char *video_mode;
 	int err;
 
 	if (!mach_info)
diff --git a/drivers/video/fbdev/fm2fb.c b/drivers/video/fbdev/fm2fb.c
index 4f17bc8e6c1d..a466e8ddfe8a 100644
--- a/drivers/video/fbdev/fm2fb.c
+++ b/drivers/video/fbdev/fm2fb.c
@@ -315,7 +315,7 @@ static int __init fm2fb_setup(const char *options)
 
 static int __init fm2fb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("fm2fb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index c97a9c04e8e8..8341332b52a8 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -1908,7 +1908,7 @@ static int __init fsl_diu_init(void)
 #endif
 	int ret;
 #ifndef MODULE
-	char *option;
+	const char *option;
 
 	/*
 	 * For kernel boot options (in 'video=xxxfb:<options>' format)
diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 36651bb6006d..d7fd55405169 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1125,7 +1125,7 @@ static int gbefb_probe(struct platform_device *p_dev)
 	struct fb_info *info;
 	struct gbefb_par *par;
 #ifndef MODULE
-	char *options = NULL;
+	const char *options = NULL;
 #endif
 
 	info = framebuffer_alloc(sizeof(struct gbefb_par), &p_dev->dev);
diff --git a/drivers/video/fbdev/geode/gx1fb_core.c b/drivers/video/fbdev/geode/gx1fb_core.c
index dd1dc7ee7f83..174c0dd8f389 100644
--- a/drivers/video/fbdev/geode/gx1fb_core.c
+++ b/drivers/video/fbdev/geode/gx1fb_core.c
@@ -445,7 +445,7 @@ static struct pci_driver gx1fb_driver = {
 static int __init gx1fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("gx1fb"))
diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index f5e88e92ba16..3d70e13e1f7a 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -517,7 +517,7 @@ static int __init gxfb_setup(const char *options)
 static int __init gxfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("gxfb"))
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index d687054cdb09..2d529ad6a391 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -653,7 +653,7 @@ static int __init lxfb_setup(const char *options)
 static int __init lxfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("lxfb"))
diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index f803dc37c891..727a8f793877 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -334,7 +334,8 @@ static int grvga_probe(struct platform_device *dev)
 	unsigned long physical_start = 0;
 	unsigned long grvga_mem_size = 0;
 	struct grvga_par *par = NULL;
-	char *options = NULL, *mode_opt = NULL;
+	const char *options = NULL;
+	const *mode_opt = NULL;
 	struct option_iter iter;
 	const char *this_opt;
 
diff --git a/drivers/video/fbdev/gxt4500.c b/drivers/video/fbdev/gxt4500.c
index 61bc714693f5..d9c0aea36719 100644
--- a/drivers/video/fbdev/gxt4500.c
+++ b/drivers/video/fbdev/gxt4500.c
@@ -780,7 +780,7 @@ static struct pci_driver gxt4500_driver = {
 static int gxt4500_init(void)
 {
 #ifndef MODULE
-	char *options;
+	const char *options;
 #endif
 
 	if (fb_modesetting_disabled("gxt4500"))
diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
index edb0555239c6..c7956626eed0 100644
--- a/drivers/video/fbdev/hyperv_fb.c
+++ b/drivers/video/fbdev/hyperv_fb.c
@@ -903,7 +903,7 @@ static const struct fb_ops hvfb_ops = {
 static void hvfb_get_option(struct fb_info *info)
 {
 	struct hvfb_par *par = info->par;
-	char *options = NULL;
+	const char *options = NULL;
 	char *optbuf, *opt, *p;
 	uint x = 0, y = 0;
 
diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c
index cf45d6280f38..89455ce69c41 100644
--- a/drivers/video/fbdev/i740fb.c
+++ b/drivers/video/fbdev/i740fb.c
@@ -1294,7 +1294,7 @@ static int  __init i740fb_setup(const char *options)
 static int __init i740fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("i740fb"))
diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c
index 3e624522fe7a..77d784261c6a 100644
--- a/drivers/video/fbdev/i810/i810_main.c
+++ b/drivers/video/fbdev/i810/i810_main.c
@@ -2155,7 +2155,7 @@ static void i810fb_remove_pci(struct pci_dev *dev)
 #ifndef MODULE
 static int i810fb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_modesetting_disabled("i810fb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
index fc046886599c..3edb7b752553 100644
--- a/drivers/video/fbdev/imsttfb.c
+++ b/drivers/video/fbdev/imsttfb.c
@@ -1620,7 +1620,7 @@ imsttfb_setup(const char *options)
 static int __init imsttfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("imsttfb"))
diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 950df484e5be..b62767553b29 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -846,7 +846,7 @@ static struct lcd_ops imxfb_lcd_ops = {
 
 static int imxfb_setup(void)
 {
-	char *options = NULL;
+	const char *options = NULL;
 	struct option_iter iter;
 	const char *opt;
 
diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 2d4e03b9e7fd..bff36914b62f 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -390,7 +390,7 @@ static int __init intelfb_setup(const char *options)
 static int __init intelfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	DBG_MSG("intelfb_init\n");
diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index c2c6e1bba3a0..eb15b26bdffc 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -797,7 +797,7 @@ static void kyrofb_remove(struct pci_dev *pdev)
 static int __init kyrofb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("kyrofb"))
diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index a72edb98b170..c05e790f223b 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -541,7 +541,7 @@ static int __init macfb_init(void)
 {
 	int video_cmap_len, video_is_nubus = 0;
 	struct nubus_rsrc *ndev = NULL;
-	char *option = NULL;
+	const char *option = NULL;
 	int err;
 
 	if (fb_get_options("macfb", &option))
diff --git a/drivers/video/fbdev/matrox/matroxfb_base.c b/drivers/video/fbdev/matrox/matroxfb_base.c
index f690ee0c9b1f..20d42ddc021f 100644
--- a/drivers/video/fbdev/matrox/matroxfb_base.c
+++ b/drivers/video/fbdev/matrox/matroxfb_base.c
@@ -2475,7 +2475,7 @@ static int __initdata initialized = 0;
 
 static int __init matroxfb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 	int err = 0;
 
 	DBG(__func__)
diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index cb9f5ac69e79..9c561b3bb508 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -1654,7 +1654,7 @@ static struct platform_driver mx3fb_driver = {
 static int __init mx3fb_setup(void)
 {
 #ifndef MODULE
-	char *options = NULL;
+	const char *options = NULL;
 	struct option_iter iter;
 	const char *opt;
 
diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c
index e9b132d660ab..55b47961c03e 100644
--- a/drivers/video/fbdev/neofb.c
+++ b/drivers/video/fbdev/neofb.c
@@ -2218,7 +2218,7 @@ static int __init neofb_setup(const char *options)
 static int __init neofb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("neofb"))
diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index 58b1b13f09dd..9986e9f61458 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -1537,7 +1537,7 @@ static struct pci_driver nvidiafb_driver = {
 static int nvidiafb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("nvidiafb"))
diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c
index 546230483f53..26222e0c46ca 100644
--- a/drivers/video/fbdev/ocfb.c
+++ b/drivers/video/fbdev/ocfb.c
@@ -417,7 +417,7 @@ static struct platform_driver ocfb_driver = {
 static int __init ocfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("ocfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index 464a667708db..b490fe342200 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1905,7 +1905,7 @@ static int __init omapfb_setup(const char *options)
 static int __init omapfb_init(void)
 {
 #ifndef MODULE
-	char *option;
+	const char *option;
 
 	if (fb_get_options("omapfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index 71d5b7c169e7..5840c6e385a5 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -683,7 +683,7 @@ static struct platform_driver platinum_driver =
 static int __init platinumfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("platinumfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index a6a793efb0fe..8e9b9c7b4787 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -1814,7 +1814,7 @@ static int __init pm2fb_setup(const char *options)
 static int __init pm2fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("pm2fb"))
diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index 4eec0ad1e984..598200143a0d 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -1550,7 +1550,7 @@ static int __init pm3fb_init(void)
 	 *  For kernel boot options (in 'video=pm3fb:<options>' format)
 	 */
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("pm3fb"))
diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index d7c287089c64..2b54460c5bfe 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -1256,7 +1256,7 @@ static struct ps3_system_bus_driver ps3fb_driver = {
 
 static int __init ps3fb_setup(void)
 {
-	char *options;
+	const char *options;
 	struct option_iter iter;
 	const char *this_opt;
 
diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index 9255b3506b81..7a62e5048703 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -1090,7 +1090,7 @@ static int __init pvr2fb_init(void)
 	int i, ret = -ENODEV;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("pvr2fb"))
diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index 1937a58e47a1..b856e268f3b2 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -2040,7 +2040,7 @@ static char g_options[256] = "";
 #ifndef MODULE
 static int __init pxafb_setup_options(void)
 {
-	char *options = NULL;
+	const char *options = NULL;
 
 	if (fb_get_options("pxafb", &options))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c
index d95319bb93cc..0cbff9c43ca4 100644
--- a/drivers/video/fbdev/riva/fbdev.c
+++ b/drivers/video/fbdev/riva/fbdev.c
@@ -2172,7 +2172,7 @@ static struct pci_driver rivafb_driver = {
 static int rivafb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("rivafb"))
diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index f3bd7b1c2c9a..7745801b4ff4 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -1566,7 +1566,7 @@ static int __init s3fb_init(void)
 {
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("s3fb"))
diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c
index 94026848d67d..e08ae210ad5c 100644
--- a/drivers/video/fbdev/savage/savagefb_driver.c
+++ b/drivers/video/fbdev/savage/savagefb_driver.c
@@ -2564,7 +2564,7 @@ static int __init savagefb_setup(const char *options)
 
 static int __init savagefb_init(void)
 {
-	char *option;
+	const char *option;
 
 	DBG("savagefb_init");
 
diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index 7e6e2251e62f..3ab07e6795cf 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -6587,7 +6587,7 @@ static struct pci_driver sisfb_driver = {
 static int __init sisfb_init(void)
 {
 #ifndef MODULE
-	char *options = NULL;
+	const char *options = NULL;
 #endif
 
 	if (fb_modesetting_disabled("sisfb"))
diff --git a/drivers/video/fbdev/skeletonfb.c b/drivers/video/fbdev/skeletonfb.c
index 1e876ad2a261..0d24620836bf 100644
--- a/drivers/video/fbdev/skeletonfb.c
+++ b/drivers/video/fbdev/skeletonfb.c
@@ -899,7 +899,7 @@ static int __init xxxfb_init(void)
 	 *  For kernel boot options (in 'video=xxxfb:<options>' format)
 	 */
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("xxxfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c
index b0f3898125f4..19ebbf2b019d 100644
--- a/drivers/video/fbdev/sm712fb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -1754,7 +1754,7 @@ static struct pci_driver smtcfb_driver = {
 
 static int __init sm712fb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_modesetting_disabled("sm712fb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index 6c3769062d50..d20dbd881133 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -1512,7 +1512,7 @@ static struct pci_driver sstfb_driver = {
 
 static int sstfb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_modesetting_disabled("sstfb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index 304ce8fcb9f8..c1f28bb046d3 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -1401,7 +1401,7 @@ static int __init stifb_init(void)
 	int i;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("stifb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index 54b19ce40bff..96f8a511a24f 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -1640,7 +1640,7 @@ static void tdfxfb_remove(struct pci_dev *pdev)
 static int __init tdfxfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("tdfxfb"))
diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index 704909edf89d..cf7e08c1523e 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -1605,7 +1605,7 @@ static int tgafb_init(void)
 {
 	int status;
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("tgafb"))
diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 0b8d4bc514e2..07ac9232a6ae 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -1823,7 +1823,7 @@ static int __init tridentfb_setup(const char *options)
 static int __init tridentfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("tridentfb"))
diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
index aada6a44380c..a9ac1f111f37 100644
--- a/drivers/video/fbdev/uvesafb.c
+++ b/drivers/video/fbdev/uvesafb.c
@@ -1891,7 +1891,7 @@ static int uvesafb_init(void)
 	int err;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("uvesafb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index a787b0142d00..8756f0690b09 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -304,7 +304,7 @@ static int __init valkyriefb_init(void)
 	struct fb_info_valkyrie	*p;
 	unsigned long frame_buffer_phys, cmap_regs_phys;
 	int err;
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("valkyriefb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 0310a3db2b10..6bba8759b9c4 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -253,7 +253,7 @@ static int vesafb_probe(struct platform_device *dev)
 	unsigned int size_vmode;
 	unsigned int size_remap;
 	unsigned int size_total;
-	char *option = NULL;
+	const char *option = NULL;
 
 	/* ignore error return of fb_get_options */
 	fb_get_options("vesafb", &option);
diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index ef22a6815e70..ddab307c4073 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -518,7 +518,7 @@ static int __init vfb_init(void)
 	int ret = 0;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("vfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 4f39319e21f8..3704dbfa21df 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -1923,7 +1923,7 @@ void via_fb_pci_remove(struct pci_dev *pdev)
 #ifndef MODULE
 static int __init viafb_setup(void)
 {
-	char *options;
+	const char *options;
 	struct option_iter iter;
 	const char *this_opt;
 
diff --git a/drivers/video/fbdev/vt8623fb.c b/drivers/video/fbdev/vt8623fb.c
index cbdca42d1708..b68dc71e9791 100644
--- a/drivers/video/fbdev/vt8623fb.c
+++ b/drivers/video/fbdev/vt8623fb.c
@@ -917,9 +917,8 @@ static void __exit vt8623fb_cleanup(void)
 
 static int __init vt8623fb_init(void)
 {
-
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("vt8623fb"))
diff --git a/include/linux/fb.h b/include/linux/fb.h
index d96529caa35e..0bebdd03f287 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -601,7 +601,7 @@ extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u3
 extern void fb_set_suspend(struct fb_info *info, int state);
 extern int fb_get_color_depth(struct fb_var_screeninfo *var,
 			      struct fb_fix_screeninfo *fix);
-extern int fb_get_options(const char *name, char **option);
+extern int fb_get_options(const char *name, const char **option);
 extern int fb_new_modelist(struct fb_info *info);
 
 extern bool fb_center_logo;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* [PATCH 99/99] fbdev: Constify option strings
@ 2023-03-06 16:00   ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-06 16:00 UTC (permalink / raw)
  To: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Return the option string as const char* from fb_get_options() to
enforce fbdev's ownership of the memory region. Also avoids memory
allocation within fb_get_options().

Callers that have to modify the option string must create their own
copy. As most drivers use struct option_iter, this already happens
transparently in many cases.

Adapt all callers of fb_get_options().

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/staging/sm750fb/sm750.c              |  2 +-
 drivers/video/fbdev/acornfb.c                |  2 +-
 drivers/video/fbdev/amifb.c                  |  2 +-
 drivers/video/fbdev/arkfb.c                  |  2 +-
 drivers/video/fbdev/atafb.c                  |  2 +-
 drivers/video/fbdev/aty/aty128fb.c           |  2 +-
 drivers/video/fbdev/aty/atyfb_base.c         |  2 +-
 drivers/video/fbdev/aty/radeon_base.c        |  2 +-
 drivers/video/fbdev/au1100fb.c               |  2 +-
 drivers/video/fbdev/au1200fb.c               |  2 +-
 drivers/video/fbdev/cirrusfb.c               |  2 +-
 drivers/video/fbdev/controlfb.c              |  2 +-
 drivers/video/fbdev/core/fb_cmdline.c        | 13 +++----------
 drivers/video/fbdev/core/modedb.c            |  8 ++------
 drivers/video/fbdev/cyber2000fb.c            |  2 +-
 drivers/video/fbdev/efifb.c                  |  2 +-
 drivers/video/fbdev/ep93xx-fb.c              |  2 +-
 drivers/video/fbdev/fm2fb.c                  |  2 +-
 drivers/video/fbdev/fsl-diu-fb.c             |  2 +-
 drivers/video/fbdev/gbefb.c                  |  2 +-
 drivers/video/fbdev/geode/gx1fb_core.c       |  2 +-
 drivers/video/fbdev/geode/gxfb_core.c        |  2 +-
 drivers/video/fbdev/geode/lxfb_core.c        |  2 +-
 drivers/video/fbdev/grvga.c                  |  3 ++-
 drivers/video/fbdev/gxt4500.c                |  2 +-
 drivers/video/fbdev/hyperv_fb.c              |  2 +-
 drivers/video/fbdev/i740fb.c                 |  2 +-
 drivers/video/fbdev/i810/i810_main.c         |  2 +-
 drivers/video/fbdev/imsttfb.c                |  2 +-
 drivers/video/fbdev/imxfb.c                  |  2 +-
 drivers/video/fbdev/intelfb/intelfbdrv.c     |  2 +-
 drivers/video/fbdev/kyro/fbdev.c             |  2 +-
 drivers/video/fbdev/macfb.c                  |  2 +-
 drivers/video/fbdev/matrox/matroxfb_base.c   |  2 +-
 drivers/video/fbdev/mx3fb.c                  |  2 +-
 drivers/video/fbdev/neofb.c                  |  2 +-
 drivers/video/fbdev/nvidia/nvidia.c          |  2 +-
 drivers/video/fbdev/ocfb.c                   |  2 +-
 drivers/video/fbdev/omap/omapfb_main.c       |  2 +-
 drivers/video/fbdev/platinumfb.c             |  2 +-
 drivers/video/fbdev/pm2fb.c                  |  2 +-
 drivers/video/fbdev/pm3fb.c                  |  2 +-
 drivers/video/fbdev/ps3fb.c                  |  2 +-
 drivers/video/fbdev/pvr2fb.c                 |  2 +-
 drivers/video/fbdev/pxafb.c                  |  2 +-
 drivers/video/fbdev/riva/fbdev.c             |  2 +-
 drivers/video/fbdev/s3fb.c                   |  2 +-
 drivers/video/fbdev/savage/savagefb_driver.c |  2 +-
 drivers/video/fbdev/sis/sis_main.c           |  2 +-
 drivers/video/fbdev/skeletonfb.c             |  2 +-
 drivers/video/fbdev/sm712fb.c                |  2 +-
 drivers/video/fbdev/sstfb.c                  |  2 +-
 drivers/video/fbdev/stifb.c                  |  2 +-
 drivers/video/fbdev/tdfxfb.c                 |  2 +-
 drivers/video/fbdev/tgafb.c                  |  2 +-
 drivers/video/fbdev/tridentfb.c              |  2 +-
 drivers/video/fbdev/uvesafb.c                |  2 +-
 drivers/video/fbdev/valkyriefb.c             |  2 +-
 drivers/video/fbdev/vesafb.c                 |  2 +-
 drivers/video/fbdev/vfb.c                    |  2 +-
 drivers/video/fbdev/via/viafbdev.c           |  2 +-
 drivers/video/fbdev/vt8623fb.c               |  3 +--
 include/linux/fb.h                           |  2 +-
 63 files changed, 67 insertions(+), 78 deletions(-)

diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 2eb223f0631e..fe5c18e00ac8 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -1167,7 +1167,7 @@ static struct pci_driver lynxfb_driver = {
 
 static int __init lynxfb_init(void)
 {
-	char *option;
+	const char *option;
 
 	if (fb_modesetting_disabled("sm750fb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 1d6dec45615c..be4aafb23a5c 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -926,7 +926,7 @@ static int acornfb_probe(struct platform_device *dev)
 	unsigned long size;
 	u_int h_sync, v_sync;
 	int rc, i;
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("acornfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index b968cf2c5f06..ef8518fd4fdc 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -3546,7 +3546,7 @@ static int __init amifb_probe(struct platform_device *pdev)
 	u_int defmode;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("amifb", &option)) {
 		amifb_video_off();
diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index f83fcdaec7a0..5c39b872e52d 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -1186,7 +1186,7 @@ static int __init arkfb_init(void)
 {
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("arkfb"))
diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 82d5567f2ffb..a77794ad18a7 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -2999,7 +2999,7 @@ static int __init atafb_probe(struct platform_device *pdev)
 	int pad, detected_mode, error;
 	unsigned int defmode = 0;
 	unsigned long mem_req;
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("atafb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
index 4a200eabe80b..40b42dcd00bb 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -2514,7 +2514,7 @@ static int __maybe_unused aty128_pci_resume(struct device *dev)
 static int aty128fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("aty128fb"))
diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
index 1920ee5c9a2a..fe3742cf4eb8 100644
--- a/drivers/video/fbdev/aty/atyfb_base.c
+++ b/drivers/video/fbdev/aty/atyfb_base.c
@@ -3970,7 +3970,7 @@ static int __init atyfb_init(void)
 {
 	int err1 = 1, err2 = 1;
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("atyfb"))
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index 185cd98ad59d..1d19a4b664ab 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -2616,7 +2616,7 @@ static int __init radeonfb_setup (const char *options)
 static int __init radeonfb_init (void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("radeonfb"))
diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c
index 17dae92ac53f..6976b201a3aa 100644
--- a/drivers/video/fbdev/au1100fb.c
+++ b/drivers/video/fbdev/au1100fb.c
@@ -366,7 +366,7 @@ static const struct fb_ops au1100fb_ops =
 
 static int au1100fb_setup(struct au1100fb_device *fbdev)
 {
-	char *options;
+	const char *options;
 	struct option_iter iter;
 	const char *this_opt;
 	int num_panels = ARRAY_SIZE(known_lcd_panels);
diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c
index 31a3f6afd8aa..c39bf715abad 100644
--- a/drivers/video/fbdev/au1200fb.c
+++ b/drivers/video/fbdev/au1200fb.c
@@ -1578,7 +1578,7 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
 
 static int au1200fb_setup(struct au1200fb_platdata *pd)
 {
-	char *options = NULL;
+	const char *options = NULL;
 	struct option_iter iter;
 	const char *this_opt;
 	char *endptr;
diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index c6882bff3862..28526af217c2 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -2369,7 +2369,7 @@ static int __init cirrusfb_init(void)
 	int error = 0;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("cirrusfb"))
diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 3633e874ab2e..dc1d1c7ebeee 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -1004,7 +1004,7 @@ static int __init control_of_init(struct device_node *dp)
 static int __init control_init(void)
 {
 	struct device_node *dp;
-	char *option = NULL;
+	const char *option = NULL;
 	int ret = -ENXIO;
 
 	if (fb_get_options("controlfb", &option))
diff --git a/drivers/video/fbdev/core/fb_cmdline.c b/drivers/video/fbdev/core/fb_cmdline.c
index 4d1634c492ec..67f9df7096f1 100644
--- a/drivers/video/fbdev/core/fb_cmdline.c
+++ b/drivers/video/fbdev/core/fb_cmdline.c
@@ -28,12 +28,9 @@
  *          (video=<name>:<options>)
  * @option: the option will be stored here
  *
- * The caller owns the string returned in @option and is
- * responsible for releasing the memory.
- *
  * NOTE: Needed to maintain backwards compatibility
  */
-int fb_get_options(const char *name, char **option)
+int fb_get_options(const char *name, const char **option)
 {
 	const char *options = NULL;
 	bool is_of = false;
@@ -49,12 +46,8 @@ int fb_get_options(const char *name, char **option)
 			enabled = false;
 	}
 
-	if (option) {
-		if (options)
-			*option = kstrdup(options, GFP_KERNEL);
-		else
-			*option = NULL;
-	}
+	if (option)
+		*option = options;
 
 	return enabled ? 0 : 1; // 0 on success, 1 otherwise
 }
diff --git a/drivers/video/fbdev/core/modedb.c b/drivers/video/fbdev/core/modedb.c
index 23cf8eba785d..5ff5a56925cc 100644
--- a/drivers/video/fbdev/core/modedb.c
+++ b/drivers/video/fbdev/core/modedb.c
@@ -620,7 +620,6 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 		 const struct fb_videomode *default_mode,
 		 unsigned int default_bpp)
 {
-	char *mode_option_buf = NULL;
 	int i;
 
 	/* Set up defaults */
@@ -636,10 +635,8 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 		default_bpp = 8;
 
 	/* Did the user specify a video mode? */
-	if (!mode_option) {
-		fb_get_options(NULL, &mode_option_buf);
-		mode_option = mode_option_buf;
-	}
+	if (!mode_option)
+		fb_get_options(NULL, &mode_option);
 	if (mode_option) {
 		const char *name = mode_option;
 		unsigned int namelen = strlen(name);
@@ -718,7 +715,6 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 			res_specified = 1;
 		}
 done:
-		kfree(mode_option_buf);
 		if (cvt) {
 			struct fb_videomode cvt_mode;
 			int ret;
diff --git a/drivers/video/fbdev/cyber2000fb.c b/drivers/video/fbdev/cyber2000fb.c
index 939dde664b53..4c147d1500bc 100644
--- a/drivers/video/fbdev/cyber2000fb.c
+++ b/drivers/video/fbdev/cyber2000fb.c
@@ -1877,7 +1877,7 @@ static int __init cyber2000fb_init(void)
 	int ret = -1, err;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("CyberPro"))
diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 1ae7574aaa82..669b259b78ab 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -366,7 +366,7 @@ static int efifb_probe(struct platform_device *dev)
 	unsigned int size_vmode;
 	unsigned int size_remap;
 	unsigned int size_total;
-	char *option = NULL;
+	const char *option = NULL;
 	efi_memory_desc_t md;
 
 	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled)
diff --git a/drivers/video/fbdev/ep93xx-fb.c b/drivers/video/fbdev/ep93xx-fb.c
index 305f1587bd89..33a9aa2ecc3b 100644
--- a/drivers/video/fbdev/ep93xx-fb.c
+++ b/drivers/video/fbdev/ep93xx-fb.c
@@ -464,7 +464,7 @@ static int ep93xxfb_probe(struct platform_device *pdev)
 	struct fb_info *info;
 	struct ep93xx_fbi *fbi;
 	struct resource *res;
-	char *video_mode;
+	const char *video_mode;
 	int err;
 
 	if (!mach_info)
diff --git a/drivers/video/fbdev/fm2fb.c b/drivers/video/fbdev/fm2fb.c
index 4f17bc8e6c1d..a466e8ddfe8a 100644
--- a/drivers/video/fbdev/fm2fb.c
+++ b/drivers/video/fbdev/fm2fb.c
@@ -315,7 +315,7 @@ static int __init fm2fb_setup(const char *options)
 
 static int __init fm2fb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("fm2fb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index c97a9c04e8e8..8341332b52a8 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -1908,7 +1908,7 @@ static int __init fsl_diu_init(void)
 #endif
 	int ret;
 #ifndef MODULE
-	char *option;
+	const char *option;
 
 	/*
 	 * For kernel boot options (in 'video=xxxfb:<options>' format)
diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 36651bb6006d..d7fd55405169 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1125,7 +1125,7 @@ static int gbefb_probe(struct platform_device *p_dev)
 	struct fb_info *info;
 	struct gbefb_par *par;
 #ifndef MODULE
-	char *options = NULL;
+	const char *options = NULL;
 #endif
 
 	info = framebuffer_alloc(sizeof(struct gbefb_par), &p_dev->dev);
diff --git a/drivers/video/fbdev/geode/gx1fb_core.c b/drivers/video/fbdev/geode/gx1fb_core.c
index dd1dc7ee7f83..174c0dd8f389 100644
--- a/drivers/video/fbdev/geode/gx1fb_core.c
+++ b/drivers/video/fbdev/geode/gx1fb_core.c
@@ -445,7 +445,7 @@ static struct pci_driver gx1fb_driver = {
 static int __init gx1fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("gx1fb"))
diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index f5e88e92ba16..3d70e13e1f7a 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -517,7 +517,7 @@ static int __init gxfb_setup(const char *options)
 static int __init gxfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("gxfb"))
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index d687054cdb09..2d529ad6a391 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -653,7 +653,7 @@ static int __init lxfb_setup(const char *options)
 static int __init lxfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("lxfb"))
diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index f803dc37c891..727a8f793877 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -334,7 +334,8 @@ static int grvga_probe(struct platform_device *dev)
 	unsigned long physical_start = 0;
 	unsigned long grvga_mem_size = 0;
 	struct grvga_par *par = NULL;
-	char *options = NULL, *mode_opt = NULL;
+	const char *options = NULL;
+	const *mode_opt = NULL;
 	struct option_iter iter;
 	const char *this_opt;
 
diff --git a/drivers/video/fbdev/gxt4500.c b/drivers/video/fbdev/gxt4500.c
index 61bc714693f5..d9c0aea36719 100644
--- a/drivers/video/fbdev/gxt4500.c
+++ b/drivers/video/fbdev/gxt4500.c
@@ -780,7 +780,7 @@ static struct pci_driver gxt4500_driver = {
 static int gxt4500_init(void)
 {
 #ifndef MODULE
-	char *options;
+	const char *options;
 #endif
 
 	if (fb_modesetting_disabled("gxt4500"))
diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
index edb0555239c6..c7956626eed0 100644
--- a/drivers/video/fbdev/hyperv_fb.c
+++ b/drivers/video/fbdev/hyperv_fb.c
@@ -903,7 +903,7 @@ static const struct fb_ops hvfb_ops = {
 static void hvfb_get_option(struct fb_info *info)
 {
 	struct hvfb_par *par = info->par;
-	char *options = NULL;
+	const char *options = NULL;
 	char *optbuf, *opt, *p;
 	uint x = 0, y = 0;
 
diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c
index cf45d6280f38..89455ce69c41 100644
--- a/drivers/video/fbdev/i740fb.c
+++ b/drivers/video/fbdev/i740fb.c
@@ -1294,7 +1294,7 @@ static int  __init i740fb_setup(const char *options)
 static int __init i740fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("i740fb"))
diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c
index 3e624522fe7a..77d784261c6a 100644
--- a/drivers/video/fbdev/i810/i810_main.c
+++ b/drivers/video/fbdev/i810/i810_main.c
@@ -2155,7 +2155,7 @@ static void i810fb_remove_pci(struct pci_dev *dev)
 #ifndef MODULE
 static int i810fb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_modesetting_disabled("i810fb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
index fc046886599c..3edb7b752553 100644
--- a/drivers/video/fbdev/imsttfb.c
+++ b/drivers/video/fbdev/imsttfb.c
@@ -1620,7 +1620,7 @@ imsttfb_setup(const char *options)
 static int __init imsttfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("imsttfb"))
diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 950df484e5be..b62767553b29 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -846,7 +846,7 @@ static struct lcd_ops imxfb_lcd_ops = {
 
 static int imxfb_setup(void)
 {
-	char *options = NULL;
+	const char *options = NULL;
 	struct option_iter iter;
 	const char *opt;
 
diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 2d4e03b9e7fd..bff36914b62f 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -390,7 +390,7 @@ static int __init intelfb_setup(const char *options)
 static int __init intelfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	DBG_MSG("intelfb_init\n");
diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index c2c6e1bba3a0..eb15b26bdffc 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -797,7 +797,7 @@ static void kyrofb_remove(struct pci_dev *pdev)
 static int __init kyrofb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("kyrofb"))
diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index a72edb98b170..c05e790f223b 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -541,7 +541,7 @@ static int __init macfb_init(void)
 {
 	int video_cmap_len, video_is_nubus = 0;
 	struct nubus_rsrc *ndev = NULL;
-	char *option = NULL;
+	const char *option = NULL;
 	int err;
 
 	if (fb_get_options("macfb", &option))
diff --git a/drivers/video/fbdev/matrox/matroxfb_base.c b/drivers/video/fbdev/matrox/matroxfb_base.c
index f690ee0c9b1f..20d42ddc021f 100644
--- a/drivers/video/fbdev/matrox/matroxfb_base.c
+++ b/drivers/video/fbdev/matrox/matroxfb_base.c
@@ -2475,7 +2475,7 @@ static int __initdata initialized = 0;
 
 static int __init matroxfb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 	int err = 0;
 
 	DBG(__func__)
diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index cb9f5ac69e79..9c561b3bb508 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -1654,7 +1654,7 @@ static struct platform_driver mx3fb_driver = {
 static int __init mx3fb_setup(void)
 {
 #ifndef MODULE
-	char *options = NULL;
+	const char *options = NULL;
 	struct option_iter iter;
 	const char *opt;
 
diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c
index e9b132d660ab..55b47961c03e 100644
--- a/drivers/video/fbdev/neofb.c
+++ b/drivers/video/fbdev/neofb.c
@@ -2218,7 +2218,7 @@ static int __init neofb_setup(const char *options)
 static int __init neofb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("neofb"))
diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index 58b1b13f09dd..9986e9f61458 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -1537,7 +1537,7 @@ static struct pci_driver nvidiafb_driver = {
 static int nvidiafb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("nvidiafb"))
diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c
index 546230483f53..26222e0c46ca 100644
--- a/drivers/video/fbdev/ocfb.c
+++ b/drivers/video/fbdev/ocfb.c
@@ -417,7 +417,7 @@ static struct platform_driver ocfb_driver = {
 static int __init ocfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("ocfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index 464a667708db..b490fe342200 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1905,7 +1905,7 @@ static int __init omapfb_setup(const char *options)
 static int __init omapfb_init(void)
 {
 #ifndef MODULE
-	char *option;
+	const char *option;
 
 	if (fb_get_options("omapfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index 71d5b7c169e7..5840c6e385a5 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -683,7 +683,7 @@ static struct platform_driver platinum_driver =
 static int __init platinumfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("platinumfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index a6a793efb0fe..8e9b9c7b4787 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -1814,7 +1814,7 @@ static int __init pm2fb_setup(const char *options)
 static int __init pm2fb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("pm2fb"))
diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index 4eec0ad1e984..598200143a0d 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -1550,7 +1550,7 @@ static int __init pm3fb_init(void)
 	 *  For kernel boot options (in 'video=pm3fb:<options>' format)
 	 */
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("pm3fb"))
diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index d7c287089c64..2b54460c5bfe 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -1256,7 +1256,7 @@ static struct ps3_system_bus_driver ps3fb_driver = {
 
 static int __init ps3fb_setup(void)
 {
-	char *options;
+	const char *options;
 	struct option_iter iter;
 	const char *this_opt;
 
diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index 9255b3506b81..7a62e5048703 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -1090,7 +1090,7 @@ static int __init pvr2fb_init(void)
 	int i, ret = -ENODEV;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("pvr2fb"))
diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index 1937a58e47a1..b856e268f3b2 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -2040,7 +2040,7 @@ static char g_options[256] = "";
 #ifndef MODULE
 static int __init pxafb_setup_options(void)
 {
-	char *options = NULL;
+	const char *options = NULL;
 
 	if (fb_get_options("pxafb", &options))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c
index d95319bb93cc..0cbff9c43ca4 100644
--- a/drivers/video/fbdev/riva/fbdev.c
+++ b/drivers/video/fbdev/riva/fbdev.c
@@ -2172,7 +2172,7 @@ static struct pci_driver rivafb_driver = {
 static int rivafb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("rivafb"))
diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index f3bd7b1c2c9a..7745801b4ff4 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -1566,7 +1566,7 @@ static int __init s3fb_init(void)
 {
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("s3fb"))
diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c
index 94026848d67d..e08ae210ad5c 100644
--- a/drivers/video/fbdev/savage/savagefb_driver.c
+++ b/drivers/video/fbdev/savage/savagefb_driver.c
@@ -2564,7 +2564,7 @@ static int __init savagefb_setup(const char *options)
 
 static int __init savagefb_init(void)
 {
-	char *option;
+	const char *option;
 
 	DBG("savagefb_init");
 
diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index 7e6e2251e62f..3ab07e6795cf 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -6587,7 +6587,7 @@ static struct pci_driver sisfb_driver = {
 static int __init sisfb_init(void)
 {
 #ifndef MODULE
-	char *options = NULL;
+	const char *options = NULL;
 #endif
 
 	if (fb_modesetting_disabled("sisfb"))
diff --git a/drivers/video/fbdev/skeletonfb.c b/drivers/video/fbdev/skeletonfb.c
index 1e876ad2a261..0d24620836bf 100644
--- a/drivers/video/fbdev/skeletonfb.c
+++ b/drivers/video/fbdev/skeletonfb.c
@@ -899,7 +899,7 @@ static int __init xxxfb_init(void)
 	 *  For kernel boot options (in 'video=xxxfb:<options>' format)
 	 */
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("xxxfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c
index b0f3898125f4..19ebbf2b019d 100644
--- a/drivers/video/fbdev/sm712fb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -1754,7 +1754,7 @@ static struct pci_driver smtcfb_driver = {
 
 static int __init sm712fb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_modesetting_disabled("sm712fb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index 6c3769062d50..d20dbd881133 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -1512,7 +1512,7 @@ static struct pci_driver sstfb_driver = {
 
 static int sstfb_init(void)
 {
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_modesetting_disabled("sstfb"))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index 304ce8fcb9f8..c1f28bb046d3 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -1401,7 +1401,7 @@ static int __init stifb_init(void)
 	int i;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("stifb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index 54b19ce40bff..96f8a511a24f 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -1640,7 +1640,7 @@ static void tdfxfb_remove(struct pci_dev *pdev)
 static int __init tdfxfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("tdfxfb"))
diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index 704909edf89d..cf7e08c1523e 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -1605,7 +1605,7 @@ static int tgafb_init(void)
 {
 	int status;
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("tgafb"))
diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 0b8d4bc514e2..07ac9232a6ae 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -1823,7 +1823,7 @@ static int __init tridentfb_setup(const char *options)
 static int __init tridentfb_init(void)
 {
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("tridentfb"))
diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
index aada6a44380c..a9ac1f111f37 100644
--- a/drivers/video/fbdev/uvesafb.c
+++ b/drivers/video/fbdev/uvesafb.c
@@ -1891,7 +1891,7 @@ static int uvesafb_init(void)
 	int err;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("uvesafb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index a787b0142d00..8756f0690b09 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -304,7 +304,7 @@ static int __init valkyriefb_init(void)
 	struct fb_info_valkyrie	*p;
 	unsigned long frame_buffer_phys, cmap_regs_phys;
 	int err;
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("valkyriefb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 0310a3db2b10..6bba8759b9c4 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -253,7 +253,7 @@ static int vesafb_probe(struct platform_device *dev)
 	unsigned int size_vmode;
 	unsigned int size_remap;
 	unsigned int size_total;
-	char *option = NULL;
+	const char *option = NULL;
 
 	/* ignore error return of fb_get_options */
 	fb_get_options("vesafb", &option);
diff --git a/drivers/video/fbdev/vfb.c b/drivers/video/fbdev/vfb.c
index ef22a6815e70..ddab307c4073 100644
--- a/drivers/video/fbdev/vfb.c
+++ b/drivers/video/fbdev/vfb.c
@@ -518,7 +518,7 @@ static int __init vfb_init(void)
 	int ret = 0;
 
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 
 	if (fb_get_options("vfb", &option))
 		return -ENODEV;
diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 4f39319e21f8..3704dbfa21df 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -1923,7 +1923,7 @@ void via_fb_pci_remove(struct pci_dev *pdev)
 #ifndef MODULE
 static int __init viafb_setup(void)
 {
-	char *options;
+	const char *options;
 	struct option_iter iter;
 	const char *this_opt;
 
diff --git a/drivers/video/fbdev/vt8623fb.c b/drivers/video/fbdev/vt8623fb.c
index cbdca42d1708..b68dc71e9791 100644
--- a/drivers/video/fbdev/vt8623fb.c
+++ b/drivers/video/fbdev/vt8623fb.c
@@ -917,9 +917,8 @@ static void __exit vt8623fb_cleanup(void)
 
 static int __init vt8623fb_init(void)
 {
-
 #ifndef MODULE
-	char *option = NULL;
+	const char *option = NULL;
 #endif
 
 	if (fb_modesetting_disabled("vt8623fb"))
diff --git a/include/linux/fb.h b/include/linux/fb.h
index d96529caa35e..0bebdd03f287 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -601,7 +601,7 @@ extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u3
 extern void fb_set_suspend(struct fb_info *info, int state);
 extern int fb_get_color_depth(struct fb_var_screeninfo *var,
 			      struct fb_fix_screeninfo *fix);
-extern int fb_get_options(const char *name, char **option);
+extern int fb_get_options(const char *name, const char **option);
 extern int fb_new_modelist(struct fb_info *info);
 
 extern bool fb_center_logo;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 232+ messages in thread

* Re: [PATCH 11/99] fbdev/aty: Duplicate video-mode option string
  2023-03-06 15:58   ` Thomas Zimmermann
@ 2023-03-06 16:13     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 232+ messages in thread
From: Geert Uytterhoeven @ 2023-03-06 16:13 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: linux-fbdev, adaplas, timur, corbet, deller, thomas, mbroemme,
	linux, dri-devel, sudipm.mukherjee, James.Bottomley, spock,
	pjones, paulus, geert+renesas, shawnguo, s.hauer, linux-kernel,
	teddy.wang

Hi Thomas,

Thanks for your patch!

On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Assume that the driver does not own the option string or its substrings
> and hence duplicate the option string for the video mode. The driver only
> parses the option string once as part of module initialization, so use
> a static buffer to store the duplicated mode option. Linux automatically
> frees the memory upon releasing the module.

Are you sure about that?
All of this code is inside "#ifndef MODULE".
In the aty128fb case, the function is not marked __init.
Enabling these 3 drivers adds 3x256 bytes of static buffer, more
if you enable more fbdev drivers.

> Done in preparation of switching the driver to struct option_iter and
> constifying the option string.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>

> --- a/drivers/video/fbdev/aty/aty128fb.c
> +++ b/drivers/video/fbdev/aty/aty128fb.c
> @@ -1723,7 +1723,17 @@ static int aty128fb_setup(char *options)
>                         continue;
>                 }
>  #endif /* CONFIG_PPC_PMAC */
> -               mode_option = this_opt;
> +               {
> +                       static char mode_option_buf[256];
> +                       int ret;
> +
> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
> +                       if (WARN(ret < 0, "aty128: ignoring invalid option, ret=%d\n", ret))
> +                               continue;
> +                       if (WARN(ret >= sizeof(mode_option_buf), "aty128fb: option too long\n"))
> +                               continue;
> +                       mode_option = mode_option_buf;
> +               }
>         }
>         return 0;
>  }
eturn 0;
>  }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 11/99] fbdev/aty: Duplicate video-mode option string
@ 2023-03-06 16:13     ` Geert Uytterhoeven
  0 siblings, 0 replies; 232+ messages in thread
From: Geert Uytterhoeven @ 2023-03-06 16:13 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet, linux-fbdev,
	dri-devel, linux-kernel

Hi Thomas,

Thanks for your patch!

On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Assume that the driver does not own the option string or its substrings
> and hence duplicate the option string for the video mode. The driver only
> parses the option string once as part of module initialization, so use
> a static buffer to store the duplicated mode option. Linux automatically
> frees the memory upon releasing the module.

Are you sure about that?
All of this code is inside "#ifndef MODULE".
In the aty128fb case, the function is not marked __init.
Enabling these 3 drivers adds 3x256 bytes of static buffer, more
if you enable more fbdev drivers.

> Done in preparation of switching the driver to struct option_iter and
> constifying the option string.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>

> --- a/drivers/video/fbdev/aty/aty128fb.c
> +++ b/drivers/video/fbdev/aty/aty128fb.c
> @@ -1723,7 +1723,17 @@ static int aty128fb_setup(char *options)
>                         continue;
>                 }
>  #endif /* CONFIG_PPC_PMAC */
> -               mode_option = this_opt;
> +               {
> +                       static char mode_option_buf[256];
> +                       int ret;
> +
> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
> +                       if (WARN(ret < 0, "aty128: ignoring invalid option, ret=%d\n", ret))
> +                               continue;
> +                       if (WARN(ret >= sizeof(mode_option_buf), "aty128fb: option too long\n"))
> +                               continue;
> +                       mode_option = mode_option_buf;
> +               }
>         }
>         return 0;
>  }
eturn 0;
>  }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter
  2023-03-06 15:58   ` Thomas Zimmermann
@ 2023-03-06 17:57     ` kernel test robot
  -1 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 17:57 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: oe-kbuild-all, Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-8-tzimmermann%40suse.de
patch subject: [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230307/202303070108.gtLwdySM-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/0b2c4af3b565e5ee830f7ed8e844d89237938f96
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout 0b2c4af3b565e5ee830f7ed8e844d89237938f96
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/video/fbdev/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070108.gtLwdySM-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/video/fbdev/amifb.c: In function 'ami_decode_var':
   drivers/video/fbdev/amifb.c:1134:23: warning: variable 'vtotal' set but not used [-Wunused-but-set-variable]
    1134 |         u_int htotal, vtotal;
         |                       ^~~~~~
   drivers/video/fbdev/amifb.c:1134:15: warning: variable 'htotal' set but not used [-Wunused-but-set-variable]
    1134 |         u_int htotal, vtotal;
         |               ^~~~~~
   drivers/video/fbdev/amifb.c: In function 'ami_get_var_cursorinfo':
   drivers/video/fbdev/amifb.c:1855:19: warning: variable 'alloc' set but not used [-Wunused-but-set-variable]
    1855 |         int size, alloc;
         |                   ^~~~~
   drivers/video/fbdev/amifb.c: In function 'amifb_setup':
>> drivers/video/fbdev/amifb.c:2362:51: warning: passing argument 1 of 'amifb_setup_mcap' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2362 |                         amifb_setup_mcap(this_opt + 11);
         |                                          ~~~~~~~~~^~~~
   drivers/video/fbdev/amifb.c:2312:43: note: expected 'char *' but argument is of type 'const char *'
    2312 | static void __init amifb_setup_mcap(char *spec)
         |                                     ~~~~~~^~~~


vim +2362 drivers/video/fbdev/amifb.c

f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2348  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2349  static int __init amifb_setup(const char *options)
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2350  {
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2351  	struct option_iter iter;
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2352  	const char *this_opt;
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2353  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2354  	option_iter_init(&iter, options);
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2355  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2356  	while (option_iter_next(&iter, this_opt)) {
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2357  		if (!strcmp(this_opt, "inverse")) {
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2358  			fb_invert_cmaps();
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2359  		} else if (!strcmp(this_opt, "ilbm"))
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2360  			amifb_ilbm = 1;
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2361  		else if (!strncmp(this_opt, "monitorcap:", 11))
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21 @2362  			amifb_setup_mcap(this_opt + 11);
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2363  		else if (!strncmp(this_opt, "fstart:", 7))
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2364  			min_fstrt = simple_strtoul(this_opt + 7, NULL, 0);
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2365  		else {
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2366  			static char mode_option_buf[256];
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2367  			int ret;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2368  
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2369  			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2370  			if (WARN(ret < 0, "amifb: ignoring invalid option, ret=%d\n", ret))
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2371  				continue;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2372  			if (WARN(ret >= sizeof(mode_option_buf), "amifb: option too long\n"))
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2373  				continue;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2374  			mode_option = mode_option_buf;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2375  		}
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2376  	}
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2377  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2378  	option_iter_release(&iter);
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2379  
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2380  	if (min_fstrt < 48)
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2381  		min_fstrt = 48;
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2382  
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2383  	return 0;
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2384  }
195197f408567b5 drivers/video/fbdev/amifb.c Randy Dunlap       2018-07-31  2385  #endif
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2386  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter
@ 2023-03-06 17:57     ` kernel test robot
  0 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 17:57 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: dri-devel, linux-fbdev, linux-kernel, Thomas Zimmermann, oe-kbuild-all

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-8-tzimmermann%40suse.de
patch subject: [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230307/202303070108.gtLwdySM-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/0b2c4af3b565e5ee830f7ed8e844d89237938f96
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout 0b2c4af3b565e5ee830f7ed8e844d89237938f96
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/video/fbdev/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070108.gtLwdySM-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/video/fbdev/amifb.c: In function 'ami_decode_var':
   drivers/video/fbdev/amifb.c:1134:23: warning: variable 'vtotal' set but not used [-Wunused-but-set-variable]
    1134 |         u_int htotal, vtotal;
         |                       ^~~~~~
   drivers/video/fbdev/amifb.c:1134:15: warning: variable 'htotal' set but not used [-Wunused-but-set-variable]
    1134 |         u_int htotal, vtotal;
         |               ^~~~~~
   drivers/video/fbdev/amifb.c: In function 'ami_get_var_cursorinfo':
   drivers/video/fbdev/amifb.c:1855:19: warning: variable 'alloc' set but not used [-Wunused-but-set-variable]
    1855 |         int size, alloc;
         |                   ^~~~~
   drivers/video/fbdev/amifb.c: In function 'amifb_setup':
>> drivers/video/fbdev/amifb.c:2362:51: warning: passing argument 1 of 'amifb_setup_mcap' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2362 |                         amifb_setup_mcap(this_opt + 11);
         |                                          ~~~~~~~~~^~~~
   drivers/video/fbdev/amifb.c:2312:43: note: expected 'char *' but argument is of type 'const char *'
    2312 | static void __init amifb_setup_mcap(char *spec)
         |                                     ~~~~~~^~~~


vim +2362 drivers/video/fbdev/amifb.c

f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2348  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2349  static int __init amifb_setup(const char *options)
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2350  {
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2351  	struct option_iter iter;
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2352  	const char *this_opt;
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2353  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2354  	option_iter_init(&iter, options);
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2355  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2356  	while (option_iter_next(&iter, this_opt)) {
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2357  		if (!strcmp(this_opt, "inverse")) {
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2358  			fb_invert_cmaps();
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2359  		} else if (!strcmp(this_opt, "ilbm"))
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2360  			amifb_ilbm = 1;
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2361  		else if (!strncmp(this_opt, "monitorcap:", 11))
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21 @2362  			amifb_setup_mcap(this_opt + 11);
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2363  		else if (!strncmp(this_opt, "fstart:", 7))
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2364  			min_fstrt = simple_strtoul(this_opt + 7, NULL, 0);
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2365  		else {
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2366  			static char mode_option_buf[256];
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2367  			int ret;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2368  
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2369  			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2370  			if (WARN(ret < 0, "amifb: ignoring invalid option, ret=%d\n", ret))
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2371  				continue;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2372  			if (WARN(ret >= sizeof(mode_option_buf), "amifb: option too long\n"))
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2373  				continue;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2374  			mode_option = mode_option_buf;
d3d9f26ac65b035 drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2375  		}
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2376  	}
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2377  
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2378  	option_iter_release(&iter);
0b2c4af3b565e5e drivers/video/fbdev/amifb.c Thomas Zimmermann  2023-03-06  2379  
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2380  	if (min_fstrt < 48)
f1cbb17ac739932 drivers/video/amifb.c       Geert Uytterhoeven 2011-11-21  2381  		min_fstrt = 48;
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2382  
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2383  	return 0;
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2384  }
195197f408567b5 drivers/video/fbdev/amifb.c Randy Dunlap       2018-07-31  2385  #endif
^1da177e4c3f415 drivers/video/amifb.c       Linus Torvalds     2005-04-16  2386  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter
  2023-03-06 15:58   ` Thomas Zimmermann
@ 2023-03-06 18:58     ` kernel test robot
  -1 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 18:58 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: oe-kbuild-all, Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-11-tzimmermann%40suse.de
patch subject: [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230307/202303070232.fCaufe3z-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/c5b52a9aafa2bf0107e27c7c2aa66bee9a449521
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout c5b52a9aafa2bf0107e27c7c2aa66bee9a449521
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/video/fbdev/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070232.fCaufe3z-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/video/fbdev/atafb.c: In function 'ext_setcolreg':
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2210:17: note: in expansion of macro 'DACDelay'
    2210 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2212:17: note: in expansion of macro 'DACDelay'
    2212 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2214:17: note: in expansion of macro 'DACDelay'
    2214 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2216:17: note: in expansion of macro 'DACDelay'
    2216 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c: In function 'atafb_copyarea':
   drivers/video/fbdev/atafb.c:2464:13: warning: variable 'rev_copy' set but not used [-Wunused-but-set-variable]
    2464 |         int rev_copy = 0;
         |             ^~~~~~~~
   drivers/video/fbdev/atafb.c: In function 'atafb_setup':
>> drivers/video/fbdev/atafb.c:2948:44: warning: passing argument 1 of 'get_video_mode' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2948 |                 if ((temp = get_video_mode(this_opt))) {
         |                                            ^~~~~~~~
   drivers/video/fbdev/atafb.c:529:33: note: expected 'char *' but argument is of type 'const char *'
     529 | static int get_video_mode(char *vname)
         |                           ~~~~~~^~~~~
>> drivers/video/fbdev/atafb.c:2973:50: warning: passing argument 1 of 'atafb_setup_ext' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2973 |                         atafb_setup_ext(this_opt + 9);
         |                                         ~~~~~~~~~^~~
   drivers/video/fbdev/atafb.c:2720:42: note: expected 'char *' but argument is of type 'const char *'
    2720 | static void __init atafb_setup_ext(char *spec)
         |                                    ~~~~~~^~~~
>> drivers/video/fbdev/atafb.c:2976:50: warning: passing argument 1 of 'atafb_setup_int' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2976 |                         atafb_setup_int(this_opt + 9);
         |                                         ~~~~~~~~~^~~
   drivers/video/fbdev/atafb.c:2837:42: note: expected 'char *' but argument is of type 'const char *'
    2837 | static void __init atafb_setup_int(char *spec)
         |                                    ~~~~~~^~~~
>> drivers/video/fbdev/atafb.c:2984:51: warning: passing argument 1 of 'atafb_setup_mcap' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2984 |                         atafb_setup_mcap(this_opt + 11);
         |                                          ~~~~~~~~~^~~~
   drivers/video/fbdev/atafb.c:2873:43: note: expected 'char *' but argument is of type 'const char *'
    2873 | static void __init atafb_setup_mcap(char *spec)
         |                                     ~~~~~~^~~~
>> drivers/video/fbdev/atafb.c:2989:51: warning: passing argument 1 of 'atafb_setup_user' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2989 |                         atafb_setup_user(this_opt + 1);
         |                                          ~~~~~~~~~^~~
   drivers/video/fbdev/atafb.c:2910:43: note: expected 'char *' but argument is of type 'const char *'
    2910 | static void __init atafb_setup_user(char *spec)
         |                                     ~~~~~~^~~~


vim +2948 drivers/video/fbdev/atafb.c

^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2836  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2837  static void __init atafb_setup_int(char *spec)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2838  {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2839  	/* Format to config extended internal video hardware like OverScan:
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2840  	 * "internal:<xres>;<yres>;<xres_max>;<yres_max>;<offset>"
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2841  	 * Explanation:
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2842  	 * <xres>: x-resolution
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2843  	 * <yres>: y-resolution
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2844  	 * The following are only needed if you have an overscan which
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2845  	 * needs a black border:
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2846  	 * <xres_max>: max. length of a line in pixels your OverScan hardware would allow
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2847  	 * <yres_max>: max. number of lines your OverScan hardware would allow
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2848  	 * <offset>: Offset from physical beginning to visible beginning
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2849  	 *	  of screen in bytes
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2850  	 */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2851  	int xres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2852  	char *p;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2853  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2854  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2855  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2856  	xres = simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2857  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2858  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2859  	sttt_xres = xres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2860  	tt_yres = st_yres = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2861  	if ((p = strsep(&spec, ";")) && *p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2862  		sttt_xres_virtual = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2863  	if ((p = strsep(&spec, ";")) && *p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2864  		sttt_yres_virtual = simple_strtoul(p, NULL, 0);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2865  	if ((p = strsep(&spec, ";")) && *p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2866  		ovsc_offset = simple_strtoul(p, NULL, 0);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2867  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2868  	if (ovsc_offset || (sttt_yres_virtual != st_yres))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2869  		use_hwscroll = 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2870  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2871  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2872  #ifdef ATAFB_FALCON
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2873  static void __init atafb_setup_mcap(char *spec)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2874  {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2875  	char *p;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2876  	int vmin, vmax, hmin, hmax;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2877  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2878  	/* Format for monitor capabilities is: <Vmin>;<Vmax>;<Hmin>;<Hmax>
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2879  	 * <V*> vertical freq. in Hz
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2880  	 * <H*> horizontal freq. in kHz
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2881  	 */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2882  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2883  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2884  	vmin = simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2885  	if (vmin <= 0)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2886  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2887  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2888  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2889  	vmax = simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2890  	if (vmax <= 0 || vmax <= vmin)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2891  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2892  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2893  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2894  	hmin = 1000 * simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2895  	if (hmin <= 0)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2896  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2897  	if (!(p = strsep(&spec, "")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2898  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2899  	hmax = 1000 * simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2900  	if (hmax <= 0 || hmax <= hmin)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2901  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2902  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2903  	fb_info.monspecs.vfmin = vmin;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2904  	fb_info.monspecs.vfmax = vmax;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2905  	fb_info.monspecs.hfmin = hmin;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2906  	fb_info.monspecs.hfmax = hmax;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2907  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2908  #endif /* ATAFB_FALCON */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2909  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2910  static void __init atafb_setup_user(char *spec)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2911  {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2912  	/* Format of user defined video mode is: <xres>;<yres>;<depth>
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2913  	 */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2914  	char *p;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2915  	int xres, yres, depth, temp;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2916  
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2917  	p = strsep(&spec, ";");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2918  	if (!p || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2919  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2920  	xres = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2921  	p = strsep(&spec, ";");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2922  	if (!p || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2923  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2924  	yres = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2925  	p = strsep(&spec, "");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2926  	if (!p || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2927  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2928  	depth = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2929  	temp = get_video_mode("user0");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2930  	if (temp) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2931  		default_par = temp;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2932  		atafb_predefined[default_par - 1].xres = xres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2933  		atafb_predefined[default_par - 1].yres = yres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2934  		atafb_predefined[default_par - 1].bits_per_pixel = depth;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2935  	}
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2936  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2937  
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2938  static int __init atafb_setup(const char *options)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2939  {
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2940  	struct option_iter iter;
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2941  	const char *this_opt;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2942  	int temp;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2943  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2944  	if (!options || !*options)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2945  		return 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2946  
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2947  	while (option_iter_next(&iter, this_opt)) {
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01 @2948  		if ((temp = get_video_mode(this_opt))) {
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2949  			static char mode_option_buf[256];
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2950  			int ret;
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2951  
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2952  			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2953  			if (WARN(ret < 0, "atafb: ignoring invalid option, ret=%d\n", ret))
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2954  				continue;
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2955  			if (WARN(ret >= sizeof(mode_option_buf), "atafb: option too long\n"))
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2956  				continue;
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2957  			mode_option = mode_option_buf;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2958  			default_par = temp;
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2959  		} else if (!strcmp(this_opt, "inverse"))
c7ef5e285c842b drivers/video/fbdev/atafb.c Geert Uytterhoeven 2022-07-11  2960  			fb_invert_cmaps();
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2961  		else if (!strncmp(this_opt, "hwscroll_", 9)) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2962  			hwscroll = simple_strtoul(this_opt + 9, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2963  			if (hwscroll < 0)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2964  				hwscroll = 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2965  			if (hwscroll > 200)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2966  				hwscroll = 200;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2967  		}
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2968  #ifdef ATAFB_EXT
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2969  		else if (!strcmp(this_opt, "mv300")) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2970  			external_bitspercol = 8;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2971  			external_card_type = IS_MV300;
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2972  		} else if (!strncmp(this_opt, "external:", 9))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2973  			atafb_setup_ext(this_opt + 9);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2974  #endif
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2975  		else if (!strncmp(this_opt, "internal:", 9))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2976  			atafb_setup_int(this_opt + 9);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2977  #ifdef ATAFB_FALCON
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2978  		else if (!strncmp(this_opt, "eclock:", 7)) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2979  			fext.f = simple_strtoul(this_opt + 7, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2980  			/* external pixelclock in kHz --> ps */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2981  			fext.t = 1000000000 / fext.f;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2982  			fext.f *= 1000;
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2983  		} else if (!strncmp(this_opt, "monitorcap:", 11))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2984  			atafb_setup_mcap(this_opt + 11);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2985  #endif
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2986  		else if (!strcmp(this_opt, "keep"))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2987  			DontCalcRes = 1;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2988  		else if (!strncmp(this_opt, "R", 1))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2989  			atafb_setup_user(this_opt + 1);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2990  	}
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2991  
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2992  	option_iter_release(&iter);
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2993  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2994  	return 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2995  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2996  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter
@ 2023-03-06 18:58     ` kernel test robot
  0 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 18:58 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: dri-devel, linux-fbdev, linux-kernel, Thomas Zimmermann, oe-kbuild-all

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-11-tzimmermann%40suse.de
patch subject: [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230307/202303070232.fCaufe3z-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/c5b52a9aafa2bf0107e27c7c2aa66bee9a449521
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout c5b52a9aafa2bf0107e27c7c2aa66bee9a449521
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/video/fbdev/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070232.fCaufe3z-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/video/fbdev/atafb.c: In function 'ext_setcolreg':
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2210:17: note: in expansion of macro 'DACDelay'
    2210 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2212:17: note: in expansion of macro 'DACDelay'
    2212 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2214:17: note: in expansion of macro 'DACDelay'
    2214 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c:2187:31: warning: variable 'tmp' set but not used [-Wunused-but-set-variable]
    2187 |                 unsigned char tmp = INB(0x3da); \
         |                               ^~~
   drivers/video/fbdev/atafb.c:2216:17: note: in expansion of macro 'DACDelay'
    2216 |                 DACDelay;
         |                 ^~~~~~~~
   drivers/video/fbdev/atafb.c: In function 'atafb_copyarea':
   drivers/video/fbdev/atafb.c:2464:13: warning: variable 'rev_copy' set but not used [-Wunused-but-set-variable]
    2464 |         int rev_copy = 0;
         |             ^~~~~~~~
   drivers/video/fbdev/atafb.c: In function 'atafb_setup':
>> drivers/video/fbdev/atafb.c:2948:44: warning: passing argument 1 of 'get_video_mode' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2948 |                 if ((temp = get_video_mode(this_opt))) {
         |                                            ^~~~~~~~
   drivers/video/fbdev/atafb.c:529:33: note: expected 'char *' but argument is of type 'const char *'
     529 | static int get_video_mode(char *vname)
         |                           ~~~~~~^~~~~
>> drivers/video/fbdev/atafb.c:2973:50: warning: passing argument 1 of 'atafb_setup_ext' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2973 |                         atafb_setup_ext(this_opt + 9);
         |                                         ~~~~~~~~~^~~
   drivers/video/fbdev/atafb.c:2720:42: note: expected 'char *' but argument is of type 'const char *'
    2720 | static void __init atafb_setup_ext(char *spec)
         |                                    ~~~~~~^~~~
>> drivers/video/fbdev/atafb.c:2976:50: warning: passing argument 1 of 'atafb_setup_int' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2976 |                         atafb_setup_int(this_opt + 9);
         |                                         ~~~~~~~~~^~~
   drivers/video/fbdev/atafb.c:2837:42: note: expected 'char *' but argument is of type 'const char *'
    2837 | static void __init atafb_setup_int(char *spec)
         |                                    ~~~~~~^~~~
>> drivers/video/fbdev/atafb.c:2984:51: warning: passing argument 1 of 'atafb_setup_mcap' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2984 |                         atafb_setup_mcap(this_opt + 11);
         |                                          ~~~~~~~~~^~~~
   drivers/video/fbdev/atafb.c:2873:43: note: expected 'char *' but argument is of type 'const char *'
    2873 | static void __init atafb_setup_mcap(char *spec)
         |                                     ~~~~~~^~~~
>> drivers/video/fbdev/atafb.c:2989:51: warning: passing argument 1 of 'atafb_setup_user' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    2989 |                         atafb_setup_user(this_opt + 1);
         |                                          ~~~~~~~~~^~~
   drivers/video/fbdev/atafb.c:2910:43: note: expected 'char *' but argument is of type 'const char *'
    2910 | static void __init atafb_setup_user(char *spec)
         |                                     ~~~~~~^~~~


vim +2948 drivers/video/fbdev/atafb.c

^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2836  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2837  static void __init atafb_setup_int(char *spec)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2838  {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2839  	/* Format to config extended internal video hardware like OverScan:
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2840  	 * "internal:<xres>;<yres>;<xres_max>;<yres_max>;<offset>"
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2841  	 * Explanation:
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2842  	 * <xres>: x-resolution
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2843  	 * <yres>: y-resolution
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2844  	 * The following are only needed if you have an overscan which
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2845  	 * needs a black border:
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2846  	 * <xres_max>: max. length of a line in pixels your OverScan hardware would allow
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2847  	 * <yres_max>: max. number of lines your OverScan hardware would allow
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2848  	 * <offset>: Offset from physical beginning to visible beginning
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2849  	 *	  of screen in bytes
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2850  	 */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2851  	int xres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2852  	char *p;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2853  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2854  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2855  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2856  	xres = simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2857  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2858  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2859  	sttt_xres = xres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2860  	tt_yres = st_yres = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2861  	if ((p = strsep(&spec, ";")) && *p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2862  		sttt_xres_virtual = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2863  	if ((p = strsep(&spec, ";")) && *p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2864  		sttt_yres_virtual = simple_strtoul(p, NULL, 0);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2865  	if ((p = strsep(&spec, ";")) && *p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2866  		ovsc_offset = simple_strtoul(p, NULL, 0);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2867  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2868  	if (ovsc_offset || (sttt_yres_virtual != st_yres))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2869  		use_hwscroll = 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2870  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2871  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2872  #ifdef ATAFB_FALCON
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2873  static void __init atafb_setup_mcap(char *spec)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2874  {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2875  	char *p;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2876  	int vmin, vmax, hmin, hmax;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2877  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2878  	/* Format for monitor capabilities is: <Vmin>;<Vmax>;<Hmin>;<Hmax>
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2879  	 * <V*> vertical freq. in Hz
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2880  	 * <H*> horizontal freq. in kHz
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2881  	 */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2882  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2883  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2884  	vmin = simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2885  	if (vmin <= 0)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2886  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2887  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2888  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2889  	vmax = simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2890  	if (vmax <= 0 || vmax <= vmin)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2891  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2892  	if (!(p = strsep(&spec, ";")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2893  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2894  	hmin = 1000 * simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2895  	if (hmin <= 0)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2896  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2897  	if (!(p = strsep(&spec, "")) || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2898  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2899  	hmax = 1000 * simple_strtoul(p, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2900  	if (hmax <= 0 || hmax <= hmin)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2901  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2902  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2903  	fb_info.monspecs.vfmin = vmin;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2904  	fb_info.monspecs.vfmax = vmax;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2905  	fb_info.monspecs.hfmin = hmin;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2906  	fb_info.monspecs.hfmax = hmax;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2907  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2908  #endif /* ATAFB_FALCON */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2909  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2910  static void __init atafb_setup_user(char *spec)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2911  {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2912  	/* Format of user defined video mode is: <xres>;<yres>;<depth>
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2913  	 */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2914  	char *p;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2915  	int xres, yres, depth, temp;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2916  
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2917  	p = strsep(&spec, ";");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2918  	if (!p || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2919  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2920  	xres = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2921  	p = strsep(&spec, ";");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2922  	if (!p || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2923  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2924  	yres = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2925  	p = strsep(&spec, "");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2926  	if (!p || !*p)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2927  		return;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2928  	depth = simple_strtoul(p, NULL, 10);
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2929  	temp = get_video_mode("user0");
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2930  	if (temp) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2931  		default_par = temp;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2932  		atafb_predefined[default_par - 1].xres = xres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2933  		atafb_predefined[default_par - 1].yres = yres;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2934  		atafb_predefined[default_par - 1].bits_per_pixel = depth;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2935  	}
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2936  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2937  
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2938  static int __init atafb_setup(const char *options)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2939  {
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2940  	struct option_iter iter;
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2941  	const char *this_opt;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2942  	int temp;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2943  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2944  	if (!options || !*options)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2945  		return 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2946  
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2947  	while (option_iter_next(&iter, this_opt)) {
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01 @2948  		if ((temp = get_video_mode(this_opt))) {
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2949  			static char mode_option_buf[256];
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2950  			int ret;
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2951  
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2952  			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2953  			if (WARN(ret < 0, "atafb: ignoring invalid option, ret=%d\n", ret))
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2954  				continue;
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2955  			if (WARN(ret >= sizeof(mode_option_buf), "atafb: option too long\n"))
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2956  				continue;
1d84bc16e985b8 drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2957  			mode_option = mode_option_buf;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2958  			default_par = temp;
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2959  		} else if (!strcmp(this_opt, "inverse"))
c7ef5e285c842b drivers/video/fbdev/atafb.c Geert Uytterhoeven 2022-07-11  2960  			fb_invert_cmaps();
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2961  		else if (!strncmp(this_opt, "hwscroll_", 9)) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2962  			hwscroll = simple_strtoul(this_opt + 9, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2963  			if (hwscroll < 0)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2964  				hwscroll = 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2965  			if (hwscroll > 200)
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2966  				hwscroll = 200;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2967  		}
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2968  #ifdef ATAFB_EXT
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2969  		else if (!strcmp(this_opt, "mv300")) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2970  			external_bitspercol = 8;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2971  			external_card_type = IS_MV300;
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2972  		} else if (!strncmp(this_opt, "external:", 9))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2973  			atafb_setup_ext(this_opt + 9);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2974  #endif
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2975  		else if (!strncmp(this_opt, "internal:", 9))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2976  			atafb_setup_int(this_opt + 9);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2977  #ifdef ATAFB_FALCON
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2978  		else if (!strncmp(this_opt, "eclock:", 7)) {
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2979  			fext.f = simple_strtoul(this_opt + 7, NULL, 10);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2980  			/* external pixelclock in kHz --> ps */
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2981  			fext.t = 1000000000 / fext.f;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2982  			fext.f *= 1000;
a100501212f2e2 drivers/video/atafb.c       Michael Schmitz    2007-05-01  2983  		} else if (!strncmp(this_opt, "monitorcap:", 11))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2984  			atafb_setup_mcap(this_opt + 11);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2985  #endif
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2986  		else if (!strcmp(this_opt, "keep"))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2987  			DontCalcRes = 1;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2988  		else if (!strncmp(this_opt, "R", 1))
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16 @2989  			atafb_setup_user(this_opt + 1);
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2990  	}
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2991  
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2992  	option_iter_release(&iter);
c5b52a9aafa2bf drivers/video/fbdev/atafb.c Thomas Zimmermann  2023-03-06  2993  
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2994  	return 0;
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2995  }
^1da177e4c3f41 drivers/video/atafb.c       Linus Torvalds     2005-04-16  2996  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter
  2023-03-06 15:59   ` Thomas Zimmermann
@ 2023-03-06 20:00     ` kernel test robot
  -1 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 20:00 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: oe-kbuild-all, linux-fbdev, dri-devel, linux-kernel, Thomas Zimmermann

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-30-tzimmermann%40suse.de
patch subject: [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230307/202303070324.h15vDbVS-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/0d11862a5c27c6992c00d209c68a7c014f27165a
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout 0d11862a5c27c6992c00d209c68a7c014f27165a
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc SHELL=/bin/bash drivers/video/fbdev/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070324.h15vDbVS-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/video/fbdev/grvga.c: In function 'grvga_probe':
>> drivers/video/fbdev/grvga.c:363:48: warning: passing argument 1 of 'grvga_parse_custom' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     363 |                         if (grvga_parse_custom(this_opt, &info->var) < 0) {
         |                                                ^~~~~~~~
   drivers/video/fbdev/grvga.c:266:37: note: expected 'char *' but argument is of type 'const char *'
     266 | static int grvga_parse_custom(char *options,
         |                               ~~~~~~^~~~~~~


vim +363 drivers/video/fbdev/grvga.c

a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  327  
48c68c4f1b5424 drivers/video/grvga.c       Greg Kroah-Hartman        2012-12-21  328  static int grvga_probe(struct platform_device *dev)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  329  {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  330  	struct fb_info *info;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  331  	int retval = -ENOMEM;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  332  	unsigned long virtual_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  333  	unsigned long grvga_fix_addr = 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  334  	unsigned long physical_start = 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  335  	unsigned long grvga_mem_size = 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  336  	struct grvga_par *par = NULL;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  337  	char *options = NULL, *mode_opt = NULL;
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  338  	struct option_iter iter;
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  339  	const char *this_opt;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  340  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  341  	info = framebuffer_alloc(sizeof(struct grvga_par), &dev->dev);
0adcdbcb179624 drivers/video/fbdev/grvga.c Bartlomiej Zolnierkiewicz 2019-06-28  342  	if (!info)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  343  		return -ENOMEM;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  344  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  345  	/* Expecting: "grvga: modestring, [addr:<framebuffer physical address>], [size:<framebuffer size>]
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  346  	 *
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  347  	 * If modestring is custom:<custom mode string> we parse the string which then contains all videoparameters
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  348  	 * If address is left out, we allocate memory,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  349  	 * if size is left out we only allocate enough to support the given mode.
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  350  	 */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  351  	if (fb_get_options("grvga", &options)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  352  		retval = -ENODEV;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  353  		goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  354  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  355  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  356  	if (!options || !*options)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  357  		options =  "640x480-8@60";
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  358  
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  359  	option_iter_init(&iter, options);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  360  
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  361  	while (option_iter_next(&iter, this_opt)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  362  		if (!strncmp(this_opt, "custom", 6)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05 @363  			if (grvga_parse_custom(this_opt, &info->var) < 0) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  364  				dev_err(&dev->dev, "Failed to parse custom mode (%s).\n", this_opt);
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  365  				option_iter_release(&iter);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  366  				retval = -EINVAL;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  367  				goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  368  			}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  369  		} else if (!strncmp(this_opt, "addr", 4))
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  370  			grvga_fix_addr = simple_strtoul(this_opt + 5, NULL, 16);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  371  		else if (!strncmp(this_opt, "size", 4))
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  372  			grvga_mem_size = simple_strtoul(this_opt + 5, NULL, 0);
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  373  		else {
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  374  			static char mode_option_buf[256];
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  375  			int ret;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  376  
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  377  			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  378  			if (WARN(ret < 0,
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  379  				 "grlib-svgactrl: ignoring invalid option, ret=%d\n",
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  380  				 ret))
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  381  				continue;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  382  			if (WARN(ret >= sizeof(mode_option_buf),
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  383  				 "grlib-svgactrl: option too long\n"))
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  384  				continue;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  385  			mode_opt = mode_option_buf;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  386  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  387  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  388  
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  389  	option_iter_release(&iter);
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  390  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  391  	par = info->par;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  392  	info->fbops = &grvga_ops;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  393  	info->fix = grvga_fix;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  394  	info->pseudo_palette = par->color_palette;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  395  	info->flags = FBINFO_DEFAULT | FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  396  	info->fix.smem_len = grvga_mem_size;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  397  
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  398  	if (!devm_request_mem_region(&dev->dev, dev->resource[0].start,
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  399  		    resource_size(&dev->resource[0]), "grlib-svgactrl regs")) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  400  		dev_err(&dev->dev, "registers already mapped\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  401  		retval = -EBUSY;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  402  		goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  403  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  404  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  405  	par->regs = of_ioremap(&dev->resource[0], 0,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  406  			       resource_size(&dev->resource[0]),
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  407  			       "grlib-svgactrl regs");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  408  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  409  	if (!par->regs) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  410  		dev_err(&dev->dev, "failed to map registers\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  411  		retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  412  		goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  413  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  414  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  415  	retval = fb_alloc_cmap(&info->cmap, 256, 0);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  416  	if (retval < 0) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  417  		dev_err(&dev->dev, "failed to allocate mem with fb_alloc_cmap\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  418  		retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  419  		goto unmap_regs;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  420  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  421  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  422  	if (mode_opt) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  423  		retval = fb_find_mode(&info->var, info, mode_opt,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  424  				      grvga_modedb, sizeof(grvga_modedb), &grvga_modedb[0], 8);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  425  		if (!retval || retval == 4) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  426  			retval = -EINVAL;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  427  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  428  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  429  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  430  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  431  	if (!grvga_mem_size)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  432  		grvga_mem_size = info->var.xres_virtual * info->var.yres_virtual * info->var.bits_per_pixel/8;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  433  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  434  	if (grvga_fix_addr) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  435  		/* Got framebuffer base address from argument list */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  436  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  437  		physical_start = grvga_fix_addr;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  438  
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  439  		if (!devm_request_mem_region(&dev->dev, physical_start,
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  440  					     grvga_mem_size, dev->name)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  441  			dev_err(&dev->dev, "failed to request memory region\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  442  			retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  443  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  444  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  445  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  446  		virtual_start = (unsigned long) ioremap(physical_start, grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  447  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  448  		if (!virtual_start) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  449  			dev_err(&dev->dev, "error mapping framebuffer memory\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  450  			retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  451  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  452  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  453  	} else {	/* Allocate frambuffer memory */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  454  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  455  		unsigned long page;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  456  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  457  		virtual_start = (unsigned long) __get_free_pages(GFP_DMA,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  458  								 get_order(grvga_mem_size));
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  459  		if (!virtual_start) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  460  			dev_err(&dev->dev,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  461  				"unable to allocate framebuffer memory (%lu bytes)\n",
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  462  				grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  463  			retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  464  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  465  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  466  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  467  		physical_start = dma_map_single(&dev->dev, (void *)virtual_start, grvga_mem_size, DMA_TO_DEVICE);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  468  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  469  		/* Set page reserved so that mmap will work. This is necessary
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  470  		 * since we'll be remapping normal memory.
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  471  		 */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  472  		for (page = virtual_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  473  		     page < PAGE_ALIGN(virtual_start + grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  474  		     page += PAGE_SIZE) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  475  			SetPageReserved(virt_to_page(page));
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  476  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  477  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  478  		par->fb_alloced = 1;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  479  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  480  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  481  	memset((unsigned long *) virtual_start, 0, grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  482  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  483  	info->screen_base = (char __iomem *) virtual_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  484  	info->fix.smem_start = physical_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  485  	info->fix.smem_len   = grvga_mem_size;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  486  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  487  	dev_set_drvdata(&dev->dev, info);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  488  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  489  	dev_info(&dev->dev,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  490  		 "Aeroflex Gaisler framebuffer device (fb%d), %dx%d-%d, using %luK of video memory @ %p\n",
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  491  		 info->node, info->var.xres, info->var.yres, info->var.bits_per_pixel,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  492  		 grvga_mem_size >> 10, info->screen_base);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  493  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  494  	retval = register_framebuffer(info);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  495  	if (retval < 0) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  496  		dev_err(&dev->dev, "failed to register framebuffer\n");
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  497  		goto free_mem;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  498  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  499  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  500  	__raw_writel(physical_start, &par->regs->fb_pos);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  501  	__raw_writel(__raw_readl(&par->regs->status) | 1,  /* Enable framebuffer */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  502  		     &par->regs->status);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  503  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  504  	return 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  505  
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  506  free_mem:
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  507  	if (grvga_fix_addr)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  508  		iounmap((void *)virtual_start);
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  509  	else
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  510  		kfree((void *)virtual_start);
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  511  dealloc_cmap:
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  512  	fb_dealloc_cmap(&info->cmap);
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  513  unmap_regs:
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  514  	of_iounmap(&dev->resource[0], par->regs,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  515  		   resource_size(&dev->resource[0]));
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  516  free_fb:
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  517  	framebuffer_release(info);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  518  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  519  	return retval;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  520  }
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  521  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter
@ 2023-03-06 20:00     ` kernel test robot
  0 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 20:00 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: Thomas Zimmermann, linux-fbdev, linux-kernel, dri-devel, oe-kbuild-all

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-30-tzimmermann%40suse.de
patch subject: [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230307/202303070324.h15vDbVS-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/0d11862a5c27c6992c00d209c68a7c014f27165a
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout 0d11862a5c27c6992c00d209c68a7c014f27165a
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc SHELL=/bin/bash drivers/video/fbdev/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070324.h15vDbVS-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/video/fbdev/grvga.c: In function 'grvga_probe':
>> drivers/video/fbdev/grvga.c:363:48: warning: passing argument 1 of 'grvga_parse_custom' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     363 |                         if (grvga_parse_custom(this_opt, &info->var) < 0) {
         |                                                ^~~~~~~~
   drivers/video/fbdev/grvga.c:266:37: note: expected 'char *' but argument is of type 'const char *'
     266 | static int grvga_parse_custom(char *options,
         |                               ~~~~~~^~~~~~~


vim +363 drivers/video/fbdev/grvga.c

a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  327  
48c68c4f1b5424 drivers/video/grvga.c       Greg Kroah-Hartman        2012-12-21  328  static int grvga_probe(struct platform_device *dev)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  329  {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  330  	struct fb_info *info;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  331  	int retval = -ENOMEM;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  332  	unsigned long virtual_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  333  	unsigned long grvga_fix_addr = 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  334  	unsigned long physical_start = 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  335  	unsigned long grvga_mem_size = 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  336  	struct grvga_par *par = NULL;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  337  	char *options = NULL, *mode_opt = NULL;
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  338  	struct option_iter iter;
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  339  	const char *this_opt;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  340  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  341  	info = framebuffer_alloc(sizeof(struct grvga_par), &dev->dev);
0adcdbcb179624 drivers/video/fbdev/grvga.c Bartlomiej Zolnierkiewicz 2019-06-28  342  	if (!info)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  343  		return -ENOMEM;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  344  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  345  	/* Expecting: "grvga: modestring, [addr:<framebuffer physical address>], [size:<framebuffer size>]
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  346  	 *
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  347  	 * If modestring is custom:<custom mode string> we parse the string which then contains all videoparameters
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  348  	 * If address is left out, we allocate memory,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  349  	 * if size is left out we only allocate enough to support the given mode.
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  350  	 */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  351  	if (fb_get_options("grvga", &options)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  352  		retval = -ENODEV;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  353  		goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  354  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  355  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  356  	if (!options || !*options)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  357  		options =  "640x480-8@60";
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  358  
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  359  	option_iter_init(&iter, options);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  360  
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  361  	while (option_iter_next(&iter, this_opt)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  362  		if (!strncmp(this_opt, "custom", 6)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05 @363  			if (grvga_parse_custom(this_opt, &info->var) < 0) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  364  				dev_err(&dev->dev, "Failed to parse custom mode (%s).\n", this_opt);
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  365  				option_iter_release(&iter);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  366  				retval = -EINVAL;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  367  				goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  368  			}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  369  		} else if (!strncmp(this_opt, "addr", 4))
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  370  			grvga_fix_addr = simple_strtoul(this_opt + 5, NULL, 16);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  371  		else if (!strncmp(this_opt, "size", 4))
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  372  			grvga_mem_size = simple_strtoul(this_opt + 5, NULL, 0);
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  373  		else {
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  374  			static char mode_option_buf[256];
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  375  			int ret;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  376  
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  377  			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  378  			if (WARN(ret < 0,
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  379  				 "grlib-svgactrl: ignoring invalid option, ret=%d\n",
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  380  				 ret))
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  381  				continue;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  382  			if (WARN(ret >= sizeof(mode_option_buf),
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  383  				 "grlib-svgactrl: option too long\n"))
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  384  				continue;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  385  			mode_opt = mode_option_buf;
cdc70347167d9a drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  386  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  387  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  388  
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  389  	option_iter_release(&iter);
0d11862a5c27c6 drivers/video/fbdev/grvga.c Thomas Zimmermann         2023-03-06  390  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  391  	par = info->par;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  392  	info->fbops = &grvga_ops;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  393  	info->fix = grvga_fix;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  394  	info->pseudo_palette = par->color_palette;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  395  	info->flags = FBINFO_DEFAULT | FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  396  	info->fix.smem_len = grvga_mem_size;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  397  
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  398  	if (!devm_request_mem_region(&dev->dev, dev->resource[0].start,
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  399  		    resource_size(&dev->resource[0]), "grlib-svgactrl regs")) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  400  		dev_err(&dev->dev, "registers already mapped\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  401  		retval = -EBUSY;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  402  		goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  403  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  404  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  405  	par->regs = of_ioremap(&dev->resource[0], 0,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  406  			       resource_size(&dev->resource[0]),
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  407  			       "grlib-svgactrl regs");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  408  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  409  	if (!par->regs) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  410  		dev_err(&dev->dev, "failed to map registers\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  411  		retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  412  		goto free_fb;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  413  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  414  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  415  	retval = fb_alloc_cmap(&info->cmap, 256, 0);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  416  	if (retval < 0) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  417  		dev_err(&dev->dev, "failed to allocate mem with fb_alloc_cmap\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  418  		retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  419  		goto unmap_regs;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  420  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  421  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  422  	if (mode_opt) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  423  		retval = fb_find_mode(&info->var, info, mode_opt,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  424  				      grvga_modedb, sizeof(grvga_modedb), &grvga_modedb[0], 8);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  425  		if (!retval || retval == 4) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  426  			retval = -EINVAL;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  427  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  428  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  429  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  430  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  431  	if (!grvga_mem_size)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  432  		grvga_mem_size = info->var.xres_virtual * info->var.yres_virtual * info->var.bits_per_pixel/8;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  433  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  434  	if (grvga_fix_addr) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  435  		/* Got framebuffer base address from argument list */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  436  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  437  		physical_start = grvga_fix_addr;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  438  
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  439  		if (!devm_request_mem_region(&dev->dev, physical_start,
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  440  					     grvga_mem_size, dev->name)) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  441  			dev_err(&dev->dev, "failed to request memory region\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  442  			retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  443  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  444  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  445  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  446  		virtual_start = (unsigned long) ioremap(physical_start, grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  447  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  448  		if (!virtual_start) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  449  			dev_err(&dev->dev, "error mapping framebuffer memory\n");
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  450  			retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  451  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  452  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  453  	} else {	/* Allocate frambuffer memory */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  454  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  455  		unsigned long page;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  456  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  457  		virtual_start = (unsigned long) __get_free_pages(GFP_DMA,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  458  								 get_order(grvga_mem_size));
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  459  		if (!virtual_start) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  460  			dev_err(&dev->dev,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  461  				"unable to allocate framebuffer memory (%lu bytes)\n",
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  462  				grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  463  			retval = -ENOMEM;
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  464  			goto dealloc_cmap;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  465  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  466  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  467  		physical_start = dma_map_single(&dev->dev, (void *)virtual_start, grvga_mem_size, DMA_TO_DEVICE);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  468  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  469  		/* Set page reserved so that mmap will work. This is necessary
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  470  		 * since we'll be remapping normal memory.
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  471  		 */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  472  		for (page = virtual_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  473  		     page < PAGE_ALIGN(virtual_start + grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  474  		     page += PAGE_SIZE) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  475  			SetPageReserved(virt_to_page(page));
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  476  		}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  477  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  478  		par->fb_alloced = 1;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  479  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  480  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  481  	memset((unsigned long *) virtual_start, 0, grvga_mem_size);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  482  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  483  	info->screen_base = (char __iomem *) virtual_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  484  	info->fix.smem_start = physical_start;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  485  	info->fix.smem_len   = grvga_mem_size;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  486  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  487  	dev_set_drvdata(&dev->dev, info);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  488  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  489  	dev_info(&dev->dev,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  490  		 "Aeroflex Gaisler framebuffer device (fb%d), %dx%d-%d, using %luK of video memory @ %p\n",
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  491  		 info->node, info->var.xres, info->var.yres, info->var.bits_per_pixel,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  492  		 grvga_mem_size >> 10, info->screen_base);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  493  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  494  	retval = register_framebuffer(info);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  495  	if (retval < 0) {
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  496  		dev_err(&dev->dev, "failed to register framebuffer\n");
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  497  		goto free_mem;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  498  	}
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  499  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  500  	__raw_writel(physical_start, &par->regs->fb_pos);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  501  	__raw_writel(__raw_readl(&par->regs->status) | 1,  /* Enable framebuffer */
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  502  		     &par->regs->status);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  503  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  504  	return 0;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  505  
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  506  free_mem:
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  507  	if (grvga_fix_addr)
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  508  		iounmap((void *)virtual_start);
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  509  	else
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  510  		kfree((void *)virtual_start);
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  511  dealloc_cmap:
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  512  	fb_dealloc_cmap(&info->cmap);
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  513  unmap_regs:
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  514  	of_iounmap(&dev->resource[0], par->regs,
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  515  		   resource_size(&dev->resource[0]));
42eb317f7d089f drivers/video/grvga.c       Emil Goode                2012-06-26  516  free_fb:
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  517  	framebuffer_release(info);
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  518  
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  519  	return retval;
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  520  }
a4b8f97a8fdeb9 drivers/video/grvga.c       Kristoffer Glembo         2011-07-05  521  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
  2023-03-06 15:58   ` Thomas Zimmermann
@ 2023-03-06 20:04     ` Timur Tabi
  -1 siblings, 0 replies; 232+ messages in thread
From: Timur Tabi @ 2023-03-06 20:04 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet, linux-fbdev,
	linux-kernel, dri-devel

On Mon, Mar 6, 2023 at 10:01 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Assume that the driver does not own the option string or its substrings
> and hence duplicate the option string for the video mode. The driver only
> parses the option string once as part of module initialization, so use
> a static buffer to store the duplicated mode option. Linux automatically
> frees the memory upon releasing the module.

So after module_init is finished, mode_option_buf[] no longer exists?

> +                       static char mode_option_buf[256];
> +                       int ret;
> +
> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
> +                       if (WARN(ret < 0, "fsl-diu-fb: ignoring invalid option, ret=%d\n", ret))
> +                               continue;
> +                       if (WARN(ret >= sizeof(mode_option_buf), "fsl-diu-fb: option too long\n"))
> +                               continue;
> +                       fb_mode = mode_option_buf;

If so, then I'm not sure that's going to work.  fb_mode is used after
module_init, in install_fb(), which is called by fsl_diu_probe().

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
@ 2023-03-06 20:04     ` Timur Tabi
  0 siblings, 0 replies; 232+ messages in thread
From: Timur Tabi @ 2023-03-06 20:04 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: linux-fbdev, adaplas, timur, corbet, deller, thomas, mbroemme,
	linux, dri-devel, sudipm.mukherjee, James.Bottomley, spock,
	pjones, paulus, geert+renesas, shawnguo, s.hauer, linux-kernel,
	teddy.wang

On Mon, Mar 6, 2023 at 10:01 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Assume that the driver does not own the option string or its substrings
> and hence duplicate the option string for the video mode. The driver only
> parses the option string once as part of module initialization, so use
> a static buffer to store the duplicated mode option. Linux automatically
> frees the memory upon releasing the module.

So after module_init is finished, mode_option_buf[] no longer exists?

> +                       static char mode_option_buf[256];
> +                       int ret;
> +
> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
> +                       if (WARN(ret < 0, "fsl-diu-fb: ignoring invalid option, ret=%d\n", ret))
> +                               continue;
> +                       if (WARN(ret >= sizeof(mode_option_buf), "fsl-diu-fb: option too long\n"))
> +                               continue;
> +                       fb_mode = mode_option_buf;

If so, then I'm not sure that's going to work.  fb_mode is used after
module_init, in install_fb(), which is called by fsl_diu_probe().

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string
  2023-03-06 15:58   ` Thomas Zimmermann
@ 2023-03-06 21:12     ` kernel test robot
  -1 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 21:12 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: llvm, oe-kbuild-all, linux-fbdev, dri-devel, linux-kernel,
	Thomas Zimmermann

Hi Thomas,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-9-tzimmermann%40suse.de
patch subject: [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string
config: x86_64-randconfig-a016-20230306 (https://download.01.org/0day-ci/archive/20230307/202303070537.699fZDEm-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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/intel-lab-lkp/linux/commit/f8a56fb51ff846d7daca02280ac0355e1a82264e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout f8a56fb51ff846d7daca02280ac0355e1a82264e
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070537.699fZDEm-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/video/fbdev/arkfb.c:1205:4: error: 'continue' statement not in loop statement
                           continue;
                           ^
   drivers/video/fbdev/arkfb.c:1207:4: error: 'continue' statement not in loop statement
                           continue;
                           ^
   2 errors generated.


vim +/continue +1205 drivers/video/fbdev/arkfb.c

  1191	
  1192		if (fb_modesetting_disabled("arkfb"))
  1193			return -ENODEV;
  1194	
  1195	#ifndef MODULE
  1196		if (fb_get_options("arkfb", &option))
  1197			return -ENODEV;
  1198	
  1199		if (option && *option) {
  1200			static char mode_option_buf[256];
  1201			int ret;
  1202	
  1203			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
  1204			if (WARN(ret < 0, "arkfb: ignoring invalid option, ret=%d\n", ret))
> 1205				continue;
  1206			if (WARN(ret >= sizeof(mode_option_buf), "arkfb: option too long\n"))
  1207				continue;
  1208			mode_option = mode_option_buf;
  1209		}
  1210	#endif
  1211	
  1212		pr_debug("arkfb: initializing\n");
  1213		return pci_register_driver(&arkfb_pci_driver);
  1214	}
  1215	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string
@ 2023-03-06 21:12     ` kernel test robot
  0 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-06 21:12 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, llvm, linux-kernel, dri-devel, Thomas Zimmermann,
	oe-kbuild-all

Hi Thomas,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on linus/master v6.3-rc1 next-20230306]
[cannot apply to deller-parisc/for-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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-9-tzimmermann%40suse.de
patch subject: [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string
config: x86_64-randconfig-a016-20230306 (https://download.01.org/0day-ci/archive/20230307/202303070537.699fZDEm-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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/intel-lab-lkp/linux/commit/f8a56fb51ff846d7daca02280ac0355e1a82264e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout f8a56fb51ff846d7daca02280ac0355e1a82264e
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070537.699fZDEm-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/video/fbdev/arkfb.c:1205:4: error: 'continue' statement not in loop statement
                           continue;
                           ^
   drivers/video/fbdev/arkfb.c:1207:4: error: 'continue' statement not in loop statement
                           continue;
                           ^
   2 errors generated.


vim +/continue +1205 drivers/video/fbdev/arkfb.c

  1191	
  1192		if (fb_modesetting_disabled("arkfb"))
  1193			return -ENODEV;
  1194	
  1195	#ifndef MODULE
  1196		if (fb_get_options("arkfb", &option))
  1197			return -ENODEV;
  1198	
  1199		if (option && *option) {
  1200			static char mode_option_buf[256];
  1201			int ret;
  1202	
  1203			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
  1204			if (WARN(ret < 0, "arkfb: ignoring invalid option, ret=%d\n", ret))
> 1205				continue;
  1206			if (WARN(ret >= sizeof(mode_option_buf), "arkfb: option too long\n"))
  1207				continue;
  1208			mode_option = mode_option_buf;
  1209		}
  1210	#endif
  1211	
  1212		pr_debug("arkfb: initializing\n");
  1213		return pci_register_driver(&arkfb_pci_driver);
  1214	}
  1215	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 01/99] lib: Add option iterator
  2023-03-06 15:58   ` Thomas Zimmermann
@ 2023-03-06 22:37     ` Randy Dunlap
  -1 siblings, 0 replies; 232+ messages in thread
From: Randy Dunlap @ 2023-03-06 22:37 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel

Hi,

On 3/6/23 07:58, Thomas Zimmermann wrote:
> Add struct option_iter and helpers that walk over individual options
> of an option string. Add documentation.
> 
> Kernel parameters often have the format of
> 
>   param=opt1,opt2:val,opt3
> 
> where the option string contains a number of comma-separated options.
> Drivers usually use strsep() in a loop to extract individual options
> from the string. Each call to strsep() modifies the given string, so
> callers have to duplicate kernel parameters that are to be parsed
> multiple times.
> 
> The new struct option_iter and its helpers wrap this code behind a
> clean interface. Drivers can iterate over the options without having
> to know the details of the option-string format. The iterator handles
> string memory internally without modifying the original options.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  Documentation/core-api/kernel-api.rst |  9 +++
>  include/linux/cmdline.h               | 29 ++++++++
>  lib/Makefile                          |  2 +-
>  lib/cmdline_iter.c                    | 97 +++++++++++++++++++++++++++
>  4 files changed, 136 insertions(+), 1 deletion(-)
>  create mode 100644 include/linux/cmdline.h
>  create mode 100644 lib/cmdline_iter.c
> 
> diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst
> index 62f961610773..cdc7ba8decf9 100644
> --- a/Documentation/core-api/kernel-api.rst
> +++ b/Documentation/core-api/kernel-api.rst
> @@ -93,9 +93,18 @@ Bitmap Operations
>  Command-line Parsing
>  --------------------
>  
> +.. kernel-doc:: lib/cmdline_iter.c
> +   :doc: overview
> +
>  .. kernel-doc:: lib/cmdline.c
>     :export:
>  
> +.. kernel-doc:: lib/cmdline_iter.c
> +   :export:
> +
> +.. kernel-doc:: include/linux/cmdline.h
> +   :internal:
> +
>  Sorting
>  -------
>  
> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> new file mode 100644
> index 000000000000..5d7e648e98a5
> --- /dev/null
> +++ b/include/linux/cmdline.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef LINUX_CMDLINE_H
> +#define LINUX_CMDLINE_H
> +
> +/**
> + * struct option_iter - Iterates over string of kernel or module options
> + */
> +struct option_iter {
> +	char *optbuf;
> +	char *next_opt;
> +};
> +
> +void option_iter_init(struct option_iter *iter, const char *options);
> +void option_iter_release(struct option_iter *iter);
> +const char *option_iter_incr(struct option_iter *iter);
> +
> +/**
> + * option_iter_next - Loop condition to move over options
> + * @iter_:	the iterator
> + * @opt_:	the name of the option variable
> + *
> + * Iterates over option strings as part of a while loop and
> + * stores the current option in opt_.
> + */
> +#define option_iter_next(iter_, opt_) \
> +	(((opt_) = option_iter_incr(iter_)) != NULL)
> +
> +#endif

> diff --git a/lib/cmdline_iter.c b/lib/cmdline_iter.c
> new file mode 100644
> index 000000000000..d9371dfea08b
> --- /dev/null
> +++ b/lib/cmdline_iter.c
> @@ -0,0 +1,97 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <linux/cmdline.h>
> +#include <linux/export.h>
> +#include <linux/slab.h>
> +
> +/**
> + * DOC: overview
> + *
> + * A kernel parameter's option string can contain multiple comma-separated
> + * options. Modules can parse an option string with struct &option_iter and
> + * its helpers. After obtaining the string, initialize and instance of the

                                                          an instance

> + * option iterator and loop iver its content as show below.

                               over

> + *
> + * .. code-block:: c
> + *
> + *	const char *options = ...; // provided option string
> + *
> + *	struct option_iter iter;
> + *	const char *opt;
> + *
> + *	option_iter_init(&iter, options);
> + *
> + *	while (option_iter_next(&iter, &opt)) {
> + *		if (!strcmp(opt, "foo"))
> + *			...
> + *		else (strcmp(opt, "bar"))
> + *			...
> + *		else
> + *			pr_warn("unknown option %s\n", opt);
> + *	}
> + *
> + *	option_iter_release(&iter);
> + *
> + * The call to option_iter_init() initializes the iterator instance
> + * from the option string. The while loop walks over the individual
> + * options in the sting and returns each in the second argument. The
> + * returned memory is owned by the iterator instance and callers may
> + * not modify or free it. The call to option_iter_release() frees all
> + * resources of the iterator. This process does not modify the original
> + * option string. If the option string contains an empty option (i.e.,
> + * two commas next to each other), option_iter_next() skips the empty
> + * option automatically.

Is that latter skipping over a ",," automatically something that you have
observed as needed?
I can imagine a driver or module wanting to know that an empty string
was entered (i.e., ",,").

> + */
> +
> +/**
> + * option_iter_init - Initializes an option iterator
> + * @iter:	the iterator to initialize
> + * @options:	the options string
> + */
> +void option_iter_init(struct option_iter *iter, const char *options)
> +{
> +	if (options && *options)
> +		iter->optbuf = kstrdup(options, GFP_KERNEL); // can be NULL
> +	else
> +		iter->optbuf = NULL;
> +	iter->next_opt = iter->optbuf;
> +}
> +EXPORT_SYMBOL(option_iter_init);
> +
> +/**
> + * option_iter_release - Releases an option iterator's resources
> + * @iter:	the iterator
> + */
> +void option_iter_release(struct option_iter *iter)
> +{
> +	kfree(iter->optbuf);
> +	iter->next_opt = NULL;
> +}
> +EXPORT_SYMBOL(option_iter_release);
> +
> +/**
> + * option_iter_incr - Return current option and advance to the next
> + * @iter:	the iterator
> + *
> + * Returns:

 * Return:
matches kernel-doc notation documentation.

> + * The current option string, or NULL if there are no more options.
> + */
> +const char *option_iter_incr(struct option_iter *iter)
> +{
> +	char *opt;
> +
> +	if (!iter->next_opt) { // can be OK if kstrdup failed
> +		if (iter->optbuf) // iter has already been released; logic error
> +			pr_err("Incrementing option iterator without string\n");
> +		return NULL;
> +	}
> +
> +	do {
> +		opt = strsep(&iter->next_opt, ",");
> +		if (!opt)
> +			return NULL;
> +	} while (!*opt); // found empty option string, try next
> +
> +	return opt;
> +}
> +EXPORT_SYMBOL(option_iter_incr);

Looks useful. Thanks.

-- 
~Randy

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 01/99] lib: Add option iterator
@ 2023-03-06 22:37     ` Randy Dunlap
  0 siblings, 0 replies; 232+ messages in thread
From: Randy Dunlap @ 2023-03-06 22:37 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, linux-kernel, dri-devel

Hi,

On 3/6/23 07:58, Thomas Zimmermann wrote:
> Add struct option_iter and helpers that walk over individual options
> of an option string. Add documentation.
> 
> Kernel parameters often have the format of
> 
>   param=opt1,opt2:val,opt3
> 
> where the option string contains a number of comma-separated options.
> Drivers usually use strsep() in a loop to extract individual options
> from the string. Each call to strsep() modifies the given string, so
> callers have to duplicate kernel parameters that are to be parsed
> multiple times.
> 
> The new struct option_iter and its helpers wrap this code behind a
> clean interface. Drivers can iterate over the options without having
> to know the details of the option-string format. The iterator handles
> string memory internally without modifying the original options.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  Documentation/core-api/kernel-api.rst |  9 +++
>  include/linux/cmdline.h               | 29 ++++++++
>  lib/Makefile                          |  2 +-
>  lib/cmdline_iter.c                    | 97 +++++++++++++++++++++++++++
>  4 files changed, 136 insertions(+), 1 deletion(-)
>  create mode 100644 include/linux/cmdline.h
>  create mode 100644 lib/cmdline_iter.c
> 
> diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst
> index 62f961610773..cdc7ba8decf9 100644
> --- a/Documentation/core-api/kernel-api.rst
> +++ b/Documentation/core-api/kernel-api.rst
> @@ -93,9 +93,18 @@ Bitmap Operations
>  Command-line Parsing
>  --------------------
>  
> +.. kernel-doc:: lib/cmdline_iter.c
> +   :doc: overview
> +
>  .. kernel-doc:: lib/cmdline.c
>     :export:
>  
> +.. kernel-doc:: lib/cmdline_iter.c
> +   :export:
> +
> +.. kernel-doc:: include/linux/cmdline.h
> +   :internal:
> +
>  Sorting
>  -------
>  
> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> new file mode 100644
> index 000000000000..5d7e648e98a5
> --- /dev/null
> +++ b/include/linux/cmdline.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef LINUX_CMDLINE_H
> +#define LINUX_CMDLINE_H
> +
> +/**
> + * struct option_iter - Iterates over string of kernel or module options
> + */
> +struct option_iter {
> +	char *optbuf;
> +	char *next_opt;
> +};
> +
> +void option_iter_init(struct option_iter *iter, const char *options);
> +void option_iter_release(struct option_iter *iter);
> +const char *option_iter_incr(struct option_iter *iter);
> +
> +/**
> + * option_iter_next - Loop condition to move over options
> + * @iter_:	the iterator
> + * @opt_:	the name of the option variable
> + *
> + * Iterates over option strings as part of a while loop and
> + * stores the current option in opt_.
> + */
> +#define option_iter_next(iter_, opt_) \
> +	(((opt_) = option_iter_incr(iter_)) != NULL)
> +
> +#endif

> diff --git a/lib/cmdline_iter.c b/lib/cmdline_iter.c
> new file mode 100644
> index 000000000000..d9371dfea08b
> --- /dev/null
> +++ b/lib/cmdline_iter.c
> @@ -0,0 +1,97 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <linux/cmdline.h>
> +#include <linux/export.h>
> +#include <linux/slab.h>
> +
> +/**
> + * DOC: overview
> + *
> + * A kernel parameter's option string can contain multiple comma-separated
> + * options. Modules can parse an option string with struct &option_iter and
> + * its helpers. After obtaining the string, initialize and instance of the

                                                          an instance

> + * option iterator and loop iver its content as show below.

                               over

> + *
> + * .. code-block:: c
> + *
> + *	const char *options = ...; // provided option string
> + *
> + *	struct option_iter iter;
> + *	const char *opt;
> + *
> + *	option_iter_init(&iter, options);
> + *
> + *	while (option_iter_next(&iter, &opt)) {
> + *		if (!strcmp(opt, "foo"))
> + *			...
> + *		else (strcmp(opt, "bar"))
> + *			...
> + *		else
> + *			pr_warn("unknown option %s\n", opt);
> + *	}
> + *
> + *	option_iter_release(&iter);
> + *
> + * The call to option_iter_init() initializes the iterator instance
> + * from the option string. The while loop walks over the individual
> + * options in the sting and returns each in the second argument. The
> + * returned memory is owned by the iterator instance and callers may
> + * not modify or free it. The call to option_iter_release() frees all
> + * resources of the iterator. This process does not modify the original
> + * option string. If the option string contains an empty option (i.e.,
> + * two commas next to each other), option_iter_next() skips the empty
> + * option automatically.

Is that latter skipping over a ",," automatically something that you have
observed as needed?
I can imagine a driver or module wanting to know that an empty string
was entered (i.e., ",,").

> + */
> +
> +/**
> + * option_iter_init - Initializes an option iterator
> + * @iter:	the iterator to initialize
> + * @options:	the options string
> + */
> +void option_iter_init(struct option_iter *iter, const char *options)
> +{
> +	if (options && *options)
> +		iter->optbuf = kstrdup(options, GFP_KERNEL); // can be NULL
> +	else
> +		iter->optbuf = NULL;
> +	iter->next_opt = iter->optbuf;
> +}
> +EXPORT_SYMBOL(option_iter_init);
> +
> +/**
> + * option_iter_release - Releases an option iterator's resources
> + * @iter:	the iterator
> + */
> +void option_iter_release(struct option_iter *iter)
> +{
> +	kfree(iter->optbuf);
> +	iter->next_opt = NULL;
> +}
> +EXPORT_SYMBOL(option_iter_release);
> +
> +/**
> + * option_iter_incr - Return current option and advance to the next
> + * @iter:	the iterator
> + *
> + * Returns:

 * Return:
matches kernel-doc notation documentation.

> + * The current option string, or NULL if there are no more options.
> + */
> +const char *option_iter_incr(struct option_iter *iter)
> +{
> +	char *opt;
> +
> +	if (!iter->next_opt) { // can be OK if kstrdup failed
> +		if (iter->optbuf) // iter has already been released; logic error
> +			pr_err("Incrementing option iterator without string\n");
> +		return NULL;
> +	}
> +
> +	do {
> +		opt = strsep(&iter->next_opt, ",");
> +		if (!opt)
> +			return NULL;
> +	} while (!*opt); // found empty option string, try next
> +
> +	return opt;
> +}
> +EXPORT_SYMBOL(option_iter_incr);

Looks useful. Thanks.

-- 
~Randy

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string
  2023-03-06 16:00   ` Thomas Zimmermann
@ 2023-03-07  0:26     ` kernel test robot
  -1 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-07  0:26 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: llvm, oe-kbuild-all, Thomas Zimmermann, linux-fbdev,
	linux-kernel, dri-devel

Hi Thomas,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-misc/drm-misc-next]
[cannot apply to deller-parisc/for-next staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-98-tzimmermann%40suse.de
patch subject: [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string
config: x86_64-randconfig-a016-20230306 (https://download.01.org/0day-ci/archive/20230307/202303070859.8Y5URjpT-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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/intel-lab-lkp/linux/commit/819a7fd9e1404efc4f2140bcb4c7e39643b7e4ab
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout 819a7fd9e1404efc4f2140bcb4c7e39643b7e4ab
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070859.8Y5URjpT-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/video/fbdev/vt8623fb.c:938:4: error: 'break' statement not in loop or switch statement
                           break;
                           ^
   drivers/video/fbdev/vt8623fb.c:940:4: error: 'break' statement not in loop or switch statement
                           break;
                           ^
   2 errors generated.


vim +/break +938 drivers/video/fbdev/vt8623fb.c

   924	
   925		if (fb_modesetting_disabled("vt8623fb"))
   926			return -ENODEV;
   927	
   928	#ifndef MODULE
   929		if (fb_get_options("vt8623fb", &option))
   930			return -ENODEV;
   931	
   932		if (option && *option) {
   933			static char mode_option_buf[256];
   934			int ret;
   935	
   936			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
   937			if (WARN(ret < 0, "vt8623fb: ignoring invalid option, ret=%d\n", ret))
 > 938				break;
   939			if (WARN(ret >= sizeof(mode_option_buf), "vt8623fb: option too long\n"))
   940				break;
   941			mode_option = mode_option_buf;
   942		}
   943	#endif
   944	
   945		pr_debug("vt8623fb: initializing\n");
   946		return pci_register_driver(&vt8623fb_pci_driver);
   947	}
   948	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string
@ 2023-03-07  0:26     ` kernel test robot
  0 siblings, 0 replies; 232+ messages in thread
From: kernel test robot @ 2023-03-07  0:26 UTC (permalink / raw)
  To: Thomas Zimmermann, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, llvm, linux-kernel, dri-devel, Thomas Zimmermann,
	oe-kbuild-all

Hi Thomas,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-misc/drm-misc-next]
[cannot apply to deller-parisc/for-next staging/staging-testing staging/staging-next staging/staging-linus linus/master v6.3-rc1 next-20230306]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230306160016.4459-98-tzimmermann%40suse.de
patch subject: [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string
config: x86_64-randconfig-a016-20230306 (https://download.01.org/0day-ci/archive/20230307/202303070859.8Y5URjpT-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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/intel-lab-lkp/linux/commit/819a7fd9e1404efc4f2140bcb4c7e39643b7e4ab
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/lib-Add-option-iterator/20230307-000524
        git checkout 819a7fd9e1404efc4f2140bcb4c7e39643b7e4ab
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303070859.8Y5URjpT-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/video/fbdev/vt8623fb.c:938:4: error: 'break' statement not in loop or switch statement
                           break;
                           ^
   drivers/video/fbdev/vt8623fb.c:940:4: error: 'break' statement not in loop or switch statement
                           break;
                           ^
   2 errors generated.


vim +/break +938 drivers/video/fbdev/vt8623fb.c

   924	
   925		if (fb_modesetting_disabled("vt8623fb"))
   926			return -ENODEV;
   927	
   928	#ifndef MODULE
   929		if (fb_get_options("vt8623fb", &option))
   930			return -ENODEV;
   931	
   932		if (option && *option) {
   933			static char mode_option_buf[256];
   934			int ret;
   935	
   936			ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", option);
   937			if (WARN(ret < 0, "vt8623fb: ignoring invalid option, ret=%d\n", ret))
 > 938				break;
   939			if (WARN(ret >= sizeof(mode_option_buf), "vt8623fb: option too long\n"))
   940				break;
   941			mode_option = mode_option_buf;
   942		}
   943	#endif
   944	
   945		pr_debug("vt8623fb: initializing\n");
   946		return pci_register_driver(&vt8623fb_pci_driver);
   947	}
   948	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 00/99] fbdev: Fix memory leak in option parsing
  2023-03-06 15:58 ` Thomas Zimmermann
@ 2023-03-07  7:53   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 232+ messages in thread
From: Geert Uytterhoeven @ 2023-03-07  7:53 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, corbet, linux-fbdev, dri-devel,
	linux-kernel

Hi Thomas,

On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Introduce struct option_iter and helpers to parse command-line
> options with comma-separated key-value pairs. Then convert fbdev
> drivers to the new interface. Fixes a memory leak in the parsing of
> the video= option.
>
> Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
> caller; clarify ownership"), a call to fb_get_options() either
> returned an internal string or a duplicated string; hence ownership of
> the string's memory buffer was not well defined, but depended on how
> users specified the video= option on the kernel command line. For
> global settings, the caller owned the returned memory and for per-driver
> settings, fb_get_options() owned the memory. As calling drivers were
> unable to detect the case, the memory was leaked.
>
> Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
> clarify ownership") changed sematics to caller-owned strings. Drivers
> still leaked the memory, but at least ownership was clear.
>
> This patchset fixes the memory leak and changes string ownership back
> to fb_get_options(). Patch 1 introduces struct option_iter and a few
> helpers. The interface takes an option string, such as video=, in the
> common form value1,key2:value2,value3 etc and returns the individial
> comma-separated pairs. Various modules use this pattern, so the code
> is located under lib/.
>
> Patches 2 to 98 go through fbdev drivers and convert them to the new
> interface. This often requires a number of cleanups. A driver would
> typically refer to the option string's video mode. Such strings are now
> copied to driver-allocated memory so that drivers don't refer directly
> to the option string's memory. The option iterator then replaces manual
> parsing loops based on strsep(",").

Thanks for your series!

Unfortunately I cannot say I'm thrilled about this: you are replacing
a single small dynamic memory leak by 36 larger static memory leaks.
Am I missing something?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 00/99] fbdev: Fix memory leak in option parsing
@ 2023-03-07  7:53   ` Geert Uytterhoeven
  0 siblings, 0 replies; 232+ messages in thread
From: Geert Uytterhoeven @ 2023-03-07  7:53 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: linux-fbdev, adaplas, timur, corbet, deller, thomas, mbroemme,
	linux, dri-devel, sudipm.mukherjee, James.Bottomley, spock,
	pjones, paulus, shawnguo, s.hauer, linux-kernel, teddy.wang

Hi Thomas,

On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Introduce struct option_iter and helpers to parse command-line
> options with comma-separated key-value pairs. Then convert fbdev
> drivers to the new interface. Fixes a memory leak in the parsing of
> the video= option.
>
> Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
> caller; clarify ownership"), a call to fb_get_options() either
> returned an internal string or a duplicated string; hence ownership of
> the string's memory buffer was not well defined, but depended on how
> users specified the video= option on the kernel command line. For
> global settings, the caller owned the returned memory and for per-driver
> settings, fb_get_options() owned the memory. As calling drivers were
> unable to detect the case, the memory was leaked.
>
> Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
> clarify ownership") changed sematics to caller-owned strings. Drivers
> still leaked the memory, but at least ownership was clear.
>
> This patchset fixes the memory leak and changes string ownership back
> to fb_get_options(). Patch 1 introduces struct option_iter and a few
> helpers. The interface takes an option string, such as video=, in the
> common form value1,key2:value2,value3 etc and returns the individial
> comma-separated pairs. Various modules use this pattern, so the code
> is located under lib/.
>
> Patches 2 to 98 go through fbdev drivers and convert them to the new
> interface. This often requires a number of cleanups. A driver would
> typically refer to the option string's video mode. Such strings are now
> copied to driver-allocated memory so that drivers don't refer directly
> to the option string's memory. The option iterator then replaces manual
> parsing loops based on strsep(",").

Thanks for your series!

Unfortunately I cannot say I'm thrilled about this: you are replacing
a single small dynamic memory leak by 36 larger static memory leaks.
Am I missing something?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 00/99] fbdev: Fix memory leak in option parsing
  2023-03-07  7:53   ` Geert Uytterhoeven
@ 2023-03-07  8:23     ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:23 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, sudipm.mukherjee,
	teddy.wang, corbet, linux-fbdev, dri-devel, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 3254 bytes --]

Hi Geert

Am 07.03.23 um 08:53 schrieb Geert Uytterhoeven:
> Hi Thomas,
> 
> On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>> Introduce struct option_iter and helpers to parse command-line
>> options with comma-separated key-value pairs. Then convert fbdev
>> drivers to the new interface. Fixes a memory leak in the parsing of
>> the video= option.
>>
>> Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
>> caller; clarify ownership"), a call to fb_get_options() either
>> returned an internal string or a duplicated string; hence ownership of
>> the string's memory buffer was not well defined, but depended on how
>> users specified the video= option on the kernel command line. For
>> global settings, the caller owned the returned memory and for per-driver
>> settings, fb_get_options() owned the memory. As calling drivers were
>> unable to detect the case, the memory was leaked.
>>
>> Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
>> clarify ownership") changed sematics to caller-owned strings. Drivers
>> still leaked the memory, but at least ownership was clear.
>>
>> This patchset fixes the memory leak and changes string ownership back
>> to fb_get_options(). Patch 1 introduces struct option_iter and a few
>> helpers. The interface takes an option string, such as video=, in the
>> common form value1,key2:value2,value3 etc and returns the individial
>> comma-separated pairs. Various modules use this pattern, so the code
>> is located under lib/.
>>
>> Patches 2 to 98 go through fbdev drivers and convert them to the new
>> interface. This often requires a number of cleanups. A driver would
>> typically refer to the option string's video mode. Such strings are now
>> copied to driver-allocated memory so that drivers don't refer directly
>> to the option string's memory. The option iterator then replaces manual
>> parsing loops based on strsep(",").
> 
> Thanks for your series!
> 
> Unfortunately I cannot say I'm thrilled about this: you are replacing
> a single small dynamic memory leak by 36 larger static memory leaks.

That's fair enough.

> Am I missing something?

The current size of the videomode buffers is ridiculously large. I just 
needed something that could hold the string. A long mode description 
might look like

   1920x1080MR-32@120ime

which has 21 characters. 32-byte buffers would probably be more than enough.

I think it should also be possible to do a simple kstrdup() on the given 
videomode string and free the copy in the module's _fini function.

That also brings up the question of these MODULE ifdefs. Almost all of 
the fbdev drivers only parse the command-line option if they are not 
build as a module. Do you know why? Because of the awkward semantics of 
the old fb_get_options()?  I think this should be changed so that they 
always respect the video= parameter.

Best regards
Thomas

> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 00/99] fbdev: Fix memory leak in option parsing
@ 2023-03-07  8:23     ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:23 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-fbdev, adaplas, timur, corbet, deller, thomas, mbroemme,
	linux, dri-devel, sudipm.mukherjee, James.Bottomley, pjones,
	paulus, shawnguo, s.hauer, linux-kernel, teddy.wang


[-- Attachment #1.1: Type: text/plain, Size: 3254 bytes --]

Hi Geert

Am 07.03.23 um 08:53 schrieb Geert Uytterhoeven:
> Hi Thomas,
> 
> On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>> Introduce struct option_iter and helpers to parse command-line
>> options with comma-separated key-value pairs. Then convert fbdev
>> drivers to the new interface. Fixes a memory leak in the parsing of
>> the video= option.
>>
>> Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
>> caller; clarify ownership"), a call to fb_get_options() either
>> returned an internal string or a duplicated string; hence ownership of
>> the string's memory buffer was not well defined, but depended on how
>> users specified the video= option on the kernel command line. For
>> global settings, the caller owned the returned memory and for per-driver
>> settings, fb_get_options() owned the memory. As calling drivers were
>> unable to detect the case, the memory was leaked.
>>
>> Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
>> clarify ownership") changed sematics to caller-owned strings. Drivers
>> still leaked the memory, but at least ownership was clear.
>>
>> This patchset fixes the memory leak and changes string ownership back
>> to fb_get_options(). Patch 1 introduces struct option_iter and a few
>> helpers. The interface takes an option string, such as video=, in the
>> common form value1,key2:value2,value3 etc and returns the individial
>> comma-separated pairs. Various modules use this pattern, so the code
>> is located under lib/.
>>
>> Patches 2 to 98 go through fbdev drivers and convert them to the new
>> interface. This often requires a number of cleanups. A driver would
>> typically refer to the option string's video mode. Such strings are now
>> copied to driver-allocated memory so that drivers don't refer directly
>> to the option string's memory. The option iterator then replaces manual
>> parsing loops based on strsep(",").
> 
> Thanks for your series!
> 
> Unfortunately I cannot say I'm thrilled about this: you are replacing
> a single small dynamic memory leak by 36 larger static memory leaks.

That's fair enough.

> Am I missing something?

The current size of the videomode buffers is ridiculously large. I just 
needed something that could hold the string. A long mode description 
might look like

   1920x1080MR-32@120ime

which has 21 characters. 32-byte buffers would probably be more than enough.

I think it should also be possible to do a simple kstrdup() on the given 
videomode string and free the copy in the module's _fini function.

That also brings up the question of these MODULE ifdefs. Almost all of 
the fbdev drivers only parse the command-line option if they are not 
build as a module. Do you know why? Because of the awkward semantics of 
the old fb_get_options()?  I think this should be changed so that they 
always respect the video= parameter.

Best regards
Thomas

> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 11/99] fbdev/aty: Duplicate video-mode option string
  2023-03-06 16:13     ` Geert Uytterhoeven
@ 2023-03-07  8:24       ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:24 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, spock,
	sudipm.mukherjee, teddy.wang, geert+renesas, corbet, linux-fbdev,
	dri-devel, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2232 bytes --]

Hi

Am 06.03.23 um 17:13 schrieb Geert Uytterhoeven:
> Hi Thomas,
> 
> Thanks for your patch!
> 
> On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>> Assume that the driver does not own the option string or its substrings
>> and hence duplicate the option string for the video mode. The driver only
>> parses the option string once as part of module initialization, so use
>> a static buffer to store the duplicated mode option. Linux automatically
>> frees the memory upon releasing the module.
> 
> Are you sure about that?
> All of this code is inside "#ifndef MODULE".
> In the aty128fb case, the function is not marked __init.
> Enabling these 3 drivers adds 3x256 bytes of static buffer, more
> if you enable more fbdev drivers.

Right. Please see my reply to [00/99].

> 
>> Done in preparation of switching the driver to struct option_iter and
>> constifying the option string.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
>> --- a/drivers/video/fbdev/aty/aty128fb.c
>> +++ b/drivers/video/fbdev/aty/aty128fb.c
>> @@ -1723,7 +1723,17 @@ static int aty128fb_setup(char *options)
>>                          continue;
>>                  }
>>   #endif /* CONFIG_PPC_PMAC */
>> -               mode_option = this_opt;
>> +               {
>> +                       static char mode_option_buf[256];
>> +                       int ret;
>> +
>> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
>> +                       if (WARN(ret < 0, "aty128: ignoring invalid option, ret=%d\n", ret))
>> +                               continue;
>> +                       if (WARN(ret >= sizeof(mode_option_buf), "aty128fb: option too long\n"))
>> +                               continue;
>> +                       mode_option = mode_option_buf;
>> +               }
>>          }
>>          return 0;
>>   }
> eturn 0;
>>   }
> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 11/99] fbdev/aty: Duplicate video-mode option string
@ 2023-03-07  8:24       ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:24 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-fbdev, adaplas, timur, corbet, deller, thomas, mbroemme,
	linux, dri-devel, sudipm.mukherjee, James.Bottomley, spock,
	pjones, paulus, geert+renesas, shawnguo, s.hauer, linux-kernel,
	teddy.wang


[-- Attachment #1.1: Type: text/plain, Size: 2232 bytes --]

Hi

Am 06.03.23 um 17:13 schrieb Geert Uytterhoeven:
> Hi Thomas,
> 
> Thanks for your patch!
> 
> On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>> Assume that the driver does not own the option string or its substrings
>> and hence duplicate the option string for the video mode. The driver only
>> parses the option string once as part of module initialization, so use
>> a static buffer to store the duplicated mode option. Linux automatically
>> frees the memory upon releasing the module.
> 
> Are you sure about that?
> All of this code is inside "#ifndef MODULE".
> In the aty128fb case, the function is not marked __init.
> Enabling these 3 drivers adds 3x256 bytes of static buffer, more
> if you enable more fbdev drivers.

Right. Please see my reply to [00/99].

> 
>> Done in preparation of switching the driver to struct option_iter and
>> constifying the option string.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
>> --- a/drivers/video/fbdev/aty/aty128fb.c
>> +++ b/drivers/video/fbdev/aty/aty128fb.c
>> @@ -1723,7 +1723,17 @@ static int aty128fb_setup(char *options)
>>                          continue;
>>                  }
>>   #endif /* CONFIG_PPC_PMAC */
>> -               mode_option = this_opt;
>> +               {
>> +                       static char mode_option_buf[256];
>> +                       int ret;
>> +
>> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", this_opt);
>> +                       if (WARN(ret < 0, "aty128: ignoring invalid option, ret=%d\n", ret))
>> +                               continue;
>> +                       if (WARN(ret >= sizeof(mode_option_buf), "aty128fb: option too long\n"))
>> +                               continue;
>> +                       mode_option = mode_option_buf;
>> +               }
>>          }
>>          return 0;
>>   }
> eturn 0;
>>   }
> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
  2023-03-06 20:04     ` Timur Tabi
@ 2023-03-07  8:28       ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:28 UTC (permalink / raw)
  To: Timur Tabi
  Cc: deller, paulus, benh, linux, pjones, adaplas, s.hauer, shawnguo,
	mbroemme, thomas, James.Bottomley, spock, sudipm.mukherjee,
	teddy.wang, geert+renesas, corbet, linux-fbdev, linux-kernel,
	dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1574 bytes --]

Hi

Am 06.03.23 um 21:04 schrieb Timur Tabi:
> On Mon, Mar 6, 2023 at 10:01 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>>
>> Assume that the driver does not own the option string or its substrings
>> and hence duplicate the option string for the video mode. The driver only
>> parses the option string once as part of module initialization, so use
>> a static buffer to store the duplicated mode option. Linux automatically
>> frees the memory upon releasing the module.
> 
> So after module_init is finished, mode_option_buf[] no longer exists?

Does the __init attribute on a function affect the static variables in 
that function?

Best regards
Thomas

> 
>> +                       static char mode_option_buf[256];
>> +                       int ret;
>> +
>> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
>> +                       if (WARN(ret < 0, "fsl-diu-fb: ignoring invalid option, ret=%d\n", ret))
>> +                               continue;
>> +                       if (WARN(ret >= sizeof(mode_option_buf), "fsl-diu-fb: option too long\n"))
>> +                               continue;
>> +                       fb_mode = mode_option_buf;
> 
> If so, then I'm not sure that's going to work.  fb_mode is used after
> module_init, in install_fb(), which is called by fsl_diu_probe().

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
@ 2023-03-07  8:28       ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:28 UTC (permalink / raw)
  To: Timur Tabi
  Cc: linux-fbdev, teddy.wang, adaplas, corbet, deller, thomas,
	mbroemme, linux, dri-devel, sudipm.mukherjee, James.Bottomley,
	spock, pjones, paulus, geert+renesas, shawnguo, s.hauer,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1574 bytes --]

Hi

Am 06.03.23 um 21:04 schrieb Timur Tabi:
> On Mon, Mar 6, 2023 at 10:01 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>>
>> Assume that the driver does not own the option string or its substrings
>> and hence duplicate the option string for the video mode. The driver only
>> parses the option string once as part of module initialization, so use
>> a static buffer to store the duplicated mode option. Linux automatically
>> frees the memory upon releasing the module.
> 
> So after module_init is finished, mode_option_buf[] no longer exists?

Does the __init attribute on a function affect the static variables in 
that function?

Best regards
Thomas

> 
>> +                       static char mode_option_buf[256];
>> +                       int ret;
>> +
>> +                       ret = snprintf(mode_option_buf, sizeof(mode_option_buf), "%s", opt);
>> +                       if (WARN(ret < 0, "fsl-diu-fb: ignoring invalid option, ret=%d\n", ret))
>> +                               continue;
>> +                       if (WARN(ret >= sizeof(mode_option_buf), "fsl-diu-fb: option too long\n"))
>> +                               continue;
>> +                       fb_mode = mode_option_buf;
> 
> If so, then I'm not sure that's going to work.  fb_mode is used after
> module_init, in install_fb(), which is called by fsl_diu_probe().

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 01/99] lib: Add option iterator
  2023-03-06 22:37     ` Randy Dunlap
@ 2023-03-07  8:40       ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:40 UTC (permalink / raw)
  To: Randy Dunlap, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, dri-devel, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 3147 bytes --]

Hi

Am 06.03.23 um 23:37 schrieb Randy Dunlap:
[...]
>> + *
>> + * The call to option_iter_init() initializes the iterator instance
>> + * from the option string. The while loop walks over the individual
>> + * options in the sting and returns each in the second argument. The
>> + * returned memory is owned by the iterator instance and callers may
>> + * not modify or free it. The call to option_iter_release() frees all
>> + * resources of the iterator. This process does not modify the original
>> + * option string. If the option string contains an empty option (i.e.,
>> + * two commas next to each other), option_iter_next() skips the empty
>> + * option automatically.
> 
> Is that latter skipping over a ",," automatically something that you have
> observed as needed?

It's not strictly needed for correctness, but many of those fbdev 
drivers contain code to do that. Like this one:

 
https://elixir.bootlin.com/linux/v6.2/source/drivers/video/fbdev/vesafb.c#L217

So doing it in the _incr() helper seems useful

> I can imagine a driver or module wanting to know that an empty string
> was entered (i.e., ",,").

I only looked at fbdev drivers, but none of them cared about empty 
strings. They all have named options and/or key-value pairs.

> 
>> + */
>> +
>> +/**
>> + * option_iter_init - Initializes an option iterator
>> + * @iter:	the iterator to initialize
>> + * @options:	the options string
>> + */
>> +void option_iter_init(struct option_iter *iter, const char *options)
>> +{
>> +	if (options && *options)
>> +		iter->optbuf = kstrdup(options, GFP_KERNEL); // can be NULL
>> +	else
>> +		iter->optbuf = NULL;
>> +	iter->next_opt = iter->optbuf;
>> +}
>> +EXPORT_SYMBOL(option_iter_init);
>> +
>> +/**
>> + * option_iter_release - Releases an option iterator's resources
>> + * @iter:	the iterator
>> + */
>> +void option_iter_release(struct option_iter *iter)
>> +{
>> +	kfree(iter->optbuf);
>> +	iter->next_opt = NULL;
>> +}
>> +EXPORT_SYMBOL(option_iter_release);
>> +
>> +/**
>> + * option_iter_incr - Return current option and advance to the next
>> + * @iter:	the iterator
>> + *
>> + * Returns:
> 
>   * Return:
> matches kernel-doc notation documentation.
> 
>> + * The current option string, or NULL if there are no more options.
>> + */
>> +const char *option_iter_incr(struct option_iter *iter)
>> +{
>> +	char *opt;
>> +
>> +	if (!iter->next_opt) { // can be OK if kstrdup failed
>> +		if (iter->optbuf) // iter has already been released; logic error
>> +			pr_err("Incrementing option iterator without string\n");
>> +		return NULL;
>> +	}
>> +
>> +	do {
>> +		opt = strsep(&iter->next_opt, ",");
>> +		if (!opt)
>> +			return NULL;
>> +	} while (!*opt); // found empty option string, try next
>> +
>> +	return opt;
>> +}
>> +EXPORT_SYMBOL(option_iter_incr);
> 
> Looks useful. Thanks.

Thanks.

Best regards
Thomas

> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 01/99] lib: Add option iterator
@ 2023-03-07  8:40       ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-07  8:40 UTC (permalink / raw)
  To: Randy Dunlap, deller, paulus, benh, linux, pjones, timur,
	adaplas, s.hauer, shawnguo, mbroemme, thomas, James.Bottomley,
	spock, sudipm.mukherjee, teddy.wang, geert+renesas, corbet
  Cc: linux-fbdev, linux-kernel, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 3147 bytes --]

Hi

Am 06.03.23 um 23:37 schrieb Randy Dunlap:
[...]
>> + *
>> + * The call to option_iter_init() initializes the iterator instance
>> + * from the option string. The while loop walks over the individual
>> + * options in the sting and returns each in the second argument. The
>> + * returned memory is owned by the iterator instance and callers may
>> + * not modify or free it. The call to option_iter_release() frees all
>> + * resources of the iterator. This process does not modify the original
>> + * option string. If the option string contains an empty option (i.e.,
>> + * two commas next to each other), option_iter_next() skips the empty
>> + * option automatically.
> 
> Is that latter skipping over a ",," automatically something that you have
> observed as needed?

It's not strictly needed for correctness, but many of those fbdev 
drivers contain code to do that. Like this one:

 
https://elixir.bootlin.com/linux/v6.2/source/drivers/video/fbdev/vesafb.c#L217

So doing it in the _incr() helper seems useful

> I can imagine a driver or module wanting to know that an empty string
> was entered (i.e., ",,").

I only looked at fbdev drivers, but none of them cared about empty 
strings. They all have named options and/or key-value pairs.

> 
>> + */
>> +
>> +/**
>> + * option_iter_init - Initializes an option iterator
>> + * @iter:	the iterator to initialize
>> + * @options:	the options string
>> + */
>> +void option_iter_init(struct option_iter *iter, const char *options)
>> +{
>> +	if (options && *options)
>> +		iter->optbuf = kstrdup(options, GFP_KERNEL); // can be NULL
>> +	else
>> +		iter->optbuf = NULL;
>> +	iter->next_opt = iter->optbuf;
>> +}
>> +EXPORT_SYMBOL(option_iter_init);
>> +
>> +/**
>> + * option_iter_release - Releases an option iterator's resources
>> + * @iter:	the iterator
>> + */
>> +void option_iter_release(struct option_iter *iter)
>> +{
>> +	kfree(iter->optbuf);
>> +	iter->next_opt = NULL;
>> +}
>> +EXPORT_SYMBOL(option_iter_release);
>> +
>> +/**
>> + * option_iter_incr - Return current option and advance to the next
>> + * @iter:	the iterator
>> + *
>> + * Returns:
> 
>   * Return:
> matches kernel-doc notation documentation.
> 
>> + * The current option string, or NULL if there are no more options.
>> + */
>> +const char *option_iter_incr(struct option_iter *iter)
>> +{
>> +	char *opt;
>> +
>> +	if (!iter->next_opt) { // can be OK if kstrdup failed
>> +		if (iter->optbuf) // iter has already been released; logic error
>> +			pr_err("Incrementing option iterator without string\n");
>> +		return NULL;
>> +	}
>> +
>> +	do {
>> +		opt = strsep(&iter->next_opt, ",");
>> +		if (!opt)
>> +			return NULL;
>> +	} while (!*opt); // found empty option string, try next
>> +
>> +	return opt;
>> +}
>> +EXPORT_SYMBOL(option_iter_incr);
> 
> Looks useful. Thanks.

Thanks.

Best regards
Thomas

> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 00/99] fbdev: Fix memory leak in option parsing
  2023-03-07  8:23     ` Thomas Zimmermann
@ 2023-03-07  8:57       ` Geert Uytterhoeven
  -1 siblings, 0 replies; 232+ messages in thread
From: Geert Uytterhoeven @ 2023-03-07  8:57 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: deller, paulus, benh, linux, pjones, timur, adaplas, s.hauer,
	shawnguo, mbroemme, thomas, James.Bottomley, sudipm.mukherjee,
	teddy.wang, corbet, linux-fbdev, dri-devel, linux-kernel

Hi Thomas,

On Tue, Mar 7, 2023 at 9:23 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Am 07.03.23 um 08:53 schrieb Geert Uytterhoeven:
> > On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> >> Introduce struct option_iter and helpers to parse command-line
> >> options with comma-separated key-value pairs. Then convert fbdev
> >> drivers to the new interface. Fixes a memory leak in the parsing of
> >> the video= option.
> >>
> >> Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
> >> caller; clarify ownership"), a call to fb_get_options() either
> >> returned an internal string or a duplicated string; hence ownership of
> >> the string's memory buffer was not well defined, but depended on how
> >> users specified the video= option on the kernel command line. For
> >> global settings, the caller owned the returned memory and for per-driver
> >> settings, fb_get_options() owned the memory. As calling drivers were
> >> unable to detect the case, the memory was leaked.
> >>
> >> Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
> >> clarify ownership") changed sematics to caller-owned strings. Drivers
> >> still leaked the memory, but at least ownership was clear.
> >>
> >> This patchset fixes the memory leak and changes string ownership back
> >> to fb_get_options(). Patch 1 introduces struct option_iter and a few
> >> helpers. The interface takes an option string, such as video=, in the
> >> common form value1,key2:value2,value3 etc and returns the individial
> >> comma-separated pairs. Various modules use this pattern, so the code
> >> is located under lib/.
> >>
> >> Patches 2 to 98 go through fbdev drivers and convert them to the new
> >> interface. This often requires a number of cleanups. A driver would
> >> typically refer to the option string's video mode. Such strings are now
> >> copied to driver-allocated memory so that drivers don't refer directly
> >> to the option string's memory. The option iterator then replaces manual
> >> parsing loops based on strsep(",").
> >
> > Thanks for your series!
> >
> > Unfortunately I cannot say I'm thrilled about this: you are replacing
> > a single small dynamic memory leak by 36 larger static memory leaks.
>
> That's fair enough.
>
> > Am I missing something?
>
> The current size of the videomode buffers is ridiculously large. I just
> needed something that could hold the string. A long mode description
> might look like
>
>    1920x1080MR-32@120ime
>
> which has 21 characters. 32-byte buffers would probably be more than enough.

But there are a few exceptions...

> I think it should also be possible to do a simple kstrdup() on the given
> videomode string and free the copy in the module's _fini function.

That sounds like the sanest approach to me.

> That also brings up the question of these MODULE ifdefs. Almost all of
> the fbdev drivers only parse the command-line option if they are not
> build as a module. Do you know why? Because of the awkward semantics of
> the old fb_get_options()?

That's just historical: to get to see anything on the console (on
the graphics hardware without VGA text mode that fbdev was originally
developed for), you needed to have your main fbdev driver builtin.
Drivers for secondary displays could be loadable modules, and using
fbset for those offered more flexibility than a module parameter.

> I think this should be changed so that they
> always respect the video= parameter.

I agree that makes sense.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 00/99] fbdev: Fix memory leak in option parsing
@ 2023-03-07  8:57       ` Geert Uytterhoeven
  0 siblings, 0 replies; 232+ messages in thread
From: Geert Uytterhoeven @ 2023-03-07  8:57 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: linux-fbdev, adaplas, timur, corbet, deller, thomas, mbroemme,
	linux, dri-devel, sudipm.mukherjee, James.Bottomley, pjones,
	paulus, shawnguo, s.hauer, linux-kernel, teddy.wang

Hi Thomas,

On Tue, Mar 7, 2023 at 9:23 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Am 07.03.23 um 08:53 schrieb Geert Uytterhoeven:
> > On Mon, Mar 6, 2023 at 5:00 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> >> Introduce struct option_iter and helpers to parse command-line
> >> options with comma-separated key-value pairs. Then convert fbdev
> >> drivers to the new interface. Fixes a memory leak in the parsing of
> >> the video= option.
> >>
> >> Before commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to
> >> caller; clarify ownership"), a call to fb_get_options() either
> >> returned an internal string or a duplicated string; hence ownership of
> >> the string's memory buffer was not well defined, but depended on how
> >> users specified the video= option on the kernel command line. For
> >> global settings, the caller owned the returned memory and for per-driver
> >> settings, fb_get_options() owned the memory. As calling drivers were
> >> unable to detect the case, the memory was leaked.
> >>
> >> Commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller;
> >> clarify ownership") changed sematics to caller-owned strings. Drivers
> >> still leaked the memory, but at least ownership was clear.
> >>
> >> This patchset fixes the memory leak and changes string ownership back
> >> to fb_get_options(). Patch 1 introduces struct option_iter and a few
> >> helpers. The interface takes an option string, such as video=, in the
> >> common form value1,key2:value2,value3 etc and returns the individial
> >> comma-separated pairs. Various modules use this pattern, so the code
> >> is located under lib/.
> >>
> >> Patches 2 to 98 go through fbdev drivers and convert them to the new
> >> interface. This often requires a number of cleanups. A driver would
> >> typically refer to the option string's video mode. Such strings are now
> >> copied to driver-allocated memory so that drivers don't refer directly
> >> to the option string's memory. The option iterator then replaces manual
> >> parsing loops based on strsep(",").
> >
> > Thanks for your series!
> >
> > Unfortunately I cannot say I'm thrilled about this: you are replacing
> > a single small dynamic memory leak by 36 larger static memory leaks.
>
> That's fair enough.
>
> > Am I missing something?
>
> The current size of the videomode buffers is ridiculously large. I just
> needed something that could hold the string. A long mode description
> might look like
>
>    1920x1080MR-32@120ime
>
> which has 21 characters. 32-byte buffers would probably be more than enough.

But there are a few exceptions...

> I think it should also be possible to do a simple kstrdup() on the given
> videomode string and free the copy in the module's _fini function.

That sounds like the sanest approach to me.

> That also brings up the question of these MODULE ifdefs. Almost all of
> the fbdev drivers only parse the command-line option if they are not
> build as a module. Do you know why? Because of the awkward semantics of
> the old fb_get_options()?

That's just historical: to get to see anything on the console (on
the graphics hardware without VGA text mode that fbdev was originally
developed for), you needed to have your main fbdev driver builtin.
Drivers for secondary displays could be loadable modules, and using
fbset for those offered more flexibility than a module parameter.

> I think this should be changed so that they
> always respect the video= parameter.

I agree that makes sense.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
  2023-03-07  8:28       ` Thomas Zimmermann
@ 2023-03-08 16:26         ` Timur Tabi
  -1 siblings, 0 replies; 232+ messages in thread
From: Timur Tabi @ 2023-03-08 16:26 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: linux-fbdev, teddy.wang, adaplas, corbet, deller, thomas,
	mbroemme, linux, dri-devel, sudipm.mukherjee, James.Bottomley,
	spock, pjones, paulus, geert+renesas, shawnguo, s.hauer,
	linux-kernel

On Tue, Mar 7, 2023 at 2:28 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> > So after module_init is finished, mode_option_buf[] no longer exists?
>
> Does the __init attribute on a function affect the static variables in
> that function?

That is an excellent question.

https://stackoverflow.com/questions/64558614/what-happens-to-local-static-identifiers-in-init-function

I don't think the compiler is naturally aware of whatever section a
variable or function is placed in, so it can't really know that
mode_option_buf[] is suppose to have a limited lifetime.

Either way, the code seems wrong.  If mode_option_buf[] is marked as
__initdata, then it will disappear before the probe() function is
called.

If mode_option_buf[] remains resident, then we are wasting 256 bytes.

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
@ 2023-03-08 16:26         ` Timur Tabi
  0 siblings, 0 replies; 232+ messages in thread
From: Timur Tabi @ 2023-03-08 16:26 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: deller, paulus, benh, linux, pjones, adaplas, s.hauer, shawnguo,
	mbroemme, thomas, James.Bottomley, spock, sudipm.mukherjee,
	teddy.wang, geert+renesas, corbet, linux-fbdev, linux-kernel,
	dri-devel

On Tue, Mar 7, 2023 at 2:28 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
> > So after module_init is finished, mode_option_buf[] no longer exists?
>
> Does the __init attribute on a function affect the static variables in
> that function?

That is an excellent question.

https://stackoverflow.com/questions/64558614/what-happens-to-local-static-identifiers-in-init-function

I don't think the compiler is naturally aware of whatever section a
variable or function is placed in, so it can't really know that
mode_option_buf[] is suppose to have a limited lifetime.

Either way, the code seems wrong.  If mode_option_buf[] is marked as
__initdata, then it will disappear before the probe() function is
called.

If mode_option_buf[] remains resident, then we are wasting 256 bytes.

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
  2023-03-08 16:26         ` Timur Tabi
@ 2023-03-09 12:15           ` Thomas Zimmermann
  -1 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-09 12:15 UTC (permalink / raw)
  To: Timur Tabi
  Cc: deller, paulus, benh, linux, pjones, adaplas, s.hauer, shawnguo,
	mbroemme, thomas, James.Bottomley, spock, sudipm.mukherjee,
	teddy.wang, geert+renesas, corbet, linux-fbdev, linux-kernel,
	dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1255 bytes --]

Hi

Am 08.03.23 um 17:26 schrieb Timur Tabi:
> On Tue, Mar 7, 2023 at 2:28 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>>> So after module_init is finished, mode_option_buf[] no longer exists?
>>
>> Does the __init attribute on a function affect the static variables in
>> that function?
> 
> That is an excellent question.
> 
> https://stackoverflow.com/questions/64558614/what-happens-to-local-static-identifiers-in-init-function
> 
> I don't think the compiler is naturally aware of whatever section a
> variable or function is placed in, so it can't really know that
> mode_option_buf[] is suppose to have a limited lifetime.
> 
> Either way, the code seems wrong.  If mode_option_buf[] is marked as
> __initdata, then it will disappear before the probe() function is
> called.
> 
> If mode_option_buf[] remains resident, then we are wasting 256 bytes.

I'm preparing an update to this series. The string will be allocated and 
freed with kstrdup() and kfree(). So these issues should be resolved then.

Best regards
Thomas


-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

* Re: [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string
@ 2023-03-09 12:15           ` Thomas Zimmermann
  0 siblings, 0 replies; 232+ messages in thread
From: Thomas Zimmermann @ 2023-03-09 12:15 UTC (permalink / raw)
  To: Timur Tabi
  Cc: linux-fbdev, teddy.wang, adaplas, corbet, deller, thomas,
	mbroemme, linux, dri-devel, sudipm.mukherjee, James.Bottomley,
	spock, pjones, paulus, geert+renesas, shawnguo, s.hauer,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1255 bytes --]

Hi

Am 08.03.23 um 17:26 schrieb Timur Tabi:
> On Tue, Mar 7, 2023 at 2:28 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>>> So after module_init is finished, mode_option_buf[] no longer exists?
>>
>> Does the __init attribute on a function affect the static variables in
>> that function?
> 
> That is an excellent question.
> 
> https://stackoverflow.com/questions/64558614/what-happens-to-local-static-identifiers-in-init-function
> 
> I don't think the compiler is naturally aware of whatever section a
> variable or function is placed in, so it can't really know that
> mode_option_buf[] is suppose to have a limited lifetime.
> 
> Either way, the code seems wrong.  If mode_option_buf[] is marked as
> __initdata, then it will disappear before the probe() function is
> called.
> 
> If mode_option_buf[] remains resident, then we are wasting 256 bytes.

I'm preparing an update to this series. The string will be allocated and 
freed with kstrdup() and kfree(). So these issues should be resolved then.

Best regards
Thomas


-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 232+ messages in thread

end of thread, other threads:[~2023-03-09 12:16 UTC | newest]

Thread overview: 232+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 15:58 [PATCH 00/99] fbdev: Fix memory leak in option parsing Thomas Zimmermann
2023-03-06 15:58 ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 01/99] lib: Add option iterator Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 22:37   ` Randy Dunlap
2023-03-06 22:37     ` Randy Dunlap
2023-03-07  8:40     ` Thomas Zimmermann
2023-03-07  8:40       ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 02/99] fbdev/68328fb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 03/99] fbdev/68328fb: Remove unused option string Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 04/99] fbdev/acornfb: Only init fb_info once Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 05/99] fbdev/acornfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 06/99] fbdev/amifb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 07/99] fbdev/amifb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 17:57   ` kernel test robot
2023-03-06 17:57     ` kernel test robot
2023-03-06 15:58 ` [PATCH 08/99] fbdev/arkfb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 21:12   ` kernel test robot
2023-03-06 21:12     ` kernel test robot
2023-03-06 15:58 ` [PATCH 09/99] fbdev/atafb: " Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 10/99] fbdev/atafb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 18:58   ` kernel test robot
2023-03-06 18:58     ` kernel test robot
2023-03-06 15:58 ` [PATCH 11/99] fbdev/aty: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 16:13   ` Geert Uytterhoeven
2023-03-06 16:13     ` Geert Uytterhoeven
2023-03-07  8:24     ` Thomas Zimmermann
2023-03-07  8:24       ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 12/99] fbdev/aty: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 13/99] fbdev/au1100fb: " Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 14/99] fbdev/au1200fb: " Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 15/99] fbdev/cirrusfb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 16/99] fbdev/cirrusfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 17/99] fbdev/controlfb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 18/99] fbdev/controlfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 19/99] fbdev/cyber2000fb: " Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 20/99] fbdev/efifb: " Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 21/99] fbdev/fm2fb: " Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 15:58 ` [PATCH 22/99] fbdev/fsl-diu-fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:58   ` Thomas Zimmermann
2023-03-06 20:04   ` Timur Tabi
2023-03-06 20:04     ` Timur Tabi
2023-03-07  8:28     ` Thomas Zimmermann
2023-03-07  8:28       ` Thomas Zimmermann
2023-03-08 16:26       ` Timur Tabi
2023-03-08 16:26         ` Timur Tabi
2023-03-09 12:15         ` Thomas Zimmermann
2023-03-09 12:15           ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 23/99] fbdev/fsl-diu-fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 24/99] fbdev/gbefb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 25/99] fbdev/gbefb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 26/99] fbdev/geode: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 27/99] fbdev/geode: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 28/99] fbdev/grvga: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 29/99] fbdev/grvga: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 20:00   ` kernel test robot
2023-03-06 20:00     ` kernel test robot
2023-03-06 15:59 ` [PATCH 30/99] fbdev/gxt4500: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 31/99] fbdev/hyperv_fb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 32/99] fbdev/i740fb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 33/99] fbdev/i740fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 34/99] fbdev/i810: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 35/99] fbdev/i810: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 36/99] fbdev/imsttfb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 37/99] fbdev/intelfb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 38/99] fbdev/intelfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 39/99] fbdev/imxfb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 40/99] fbdev/imxfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 41/99] fbdev/kyrofb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 42/99] fbdev/kyrofb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 43/99] fbdev/macfb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 44/99] fbdev/macfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 45/99] fbdev/matroxfb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 46/99] fbdev/mx3fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 47/99] fbdev/mx3fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 48/99] fbdev/neofb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 49/99] fbdev/neofb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 50/99] fbdev/nvidiafb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 51/99] fbdev/nvidiafb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 52/99] fbdev/ocfb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 53/99] fbdev/ocfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 54/99] fbdev/omapfb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 55/99] fbdev/platinumfb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 56/99] fbdev/platinumfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 57/99] fbdev/pm2fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 58/99] fbdev/pm2fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 59/99] fbdev/pm3fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 60/99] fbdev/pm3fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 61/99] fbdev/ps3fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 62/99] fbdev/ps3fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 63/99] fbdev/pvr2fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 64/99] fbdev/pvr2fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 65/99] fbdev/pxafb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 66/99] fbdev/rivafb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 67/99] fbdev/rivafb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 68/99] fbdev/s3fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 69/99] fbdev/s3fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 70/99] fbdev/savagefb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 71/99] fbdev/savagefb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 72/99] fbdev/sisfb: Constify mode string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 73/99] fbdev/sisfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 74/99] fbdev/skeletonfb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 75/99] fbdev/sm712fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 76/99] fbdev/sstfb: " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 77/99] fbdev/sstfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 78/99] fbdev/stifb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 79/99] fbdev/sti: Constify option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 80/99] fbdev/tdfxfb: Duplicate video-mode " Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 81/99] fbdev/tdfxfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 15:59 ` [PATCH 82/99] fbdev/tgafb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 15:59   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 83/99] fbdev/tgafb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 84/99] fbdev/tmiofb: Remove unused option string Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 85/99] fbdev/tridentfb: Duplicate video-mode " Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 86/99] fbdev/tridentfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 87/99] fbdev/uvesafb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 88/99] fbdev/uvesafb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 89/99] fbdev/valkyriefb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 90/99] fbdev/valkyriefb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 91/99] fbdev/vermilion: Remove unused option string Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 92/99] fbdev/vesafb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 93/99] fbdev/vfb: Remove trailing whitespaces Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 94/99] fbdev/vfb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 95/99] fbdev/vfb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 96/99] fbdev/viafb: " Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 97/99] fbdev/vt8623fb: Duplicate video-mode option string Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-07  0:26   ` kernel test robot
2023-03-07  0:26     ` kernel test robot
2023-03-06 16:00 ` [PATCH 98/99] staging/sm750fb: Parse option string with struct option_iter Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-06 16:00 ` [PATCH 99/99] fbdev: Constify option strings Thomas Zimmermann
2023-03-06 16:00   ` Thomas Zimmermann
2023-03-07  7:53 ` [PATCH 00/99] fbdev: Fix memory leak in option parsing Geert Uytterhoeven
2023-03-07  7:53   ` Geert Uytterhoeven
2023-03-07  8:23   ` Thomas Zimmermann
2023-03-07  8:23     ` Thomas Zimmermann
2023-03-07  8:57     ` Geert Uytterhoeven
2023-03-07  8:57       ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.