linux/kernel.h: add yesno(), onoff(), enableddisabled(), plural() helpers
Subsystems (19)
PATCH 1/2 linux/kernel.h: add yesno(), onoff(), enableddisabled(), plural() helpers
The kernel has plenty of ternary operators to choose between constant strings, such as condition ? "yes" : "no", as well as value == 1 ? "" :
"s":
$ git grep '? "yes" : "no"' | wc -l 258 $ git grep '? "on" : "off"' | wc -l 204 $ git grep '? "enabled" : "disabled"' | wc -l 196 $ git grep '? "" : "s"' | wc -l 25
Additionally, there are some occurences of the same in reverse order, split to multiple lines, or otherwise not caught by the simple grep.
Add helpers to return the constant strings. Remove existing equivalent and conflicting functions in i915, cxgb4, and USB core. Further conversion can be done incrementally.
While the main goal here is to abstract recurring patterns, and slightly clean up the code base by not open coding the ternary operators, there are also some space savings to be had via better string constant pooling.
--- drivers/gpu/drm/i915/i915_utils.h | 15 ------------- .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 11 ---------- drivers/usb/core/config.c | 5 ----- drivers/usb/core/generic.c | 5 ----- include/linux/kernel.h | 21 +++++++++++++++++++ 5 files changed, 21 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/i915_utils.h +0 -15
@@ -355,19 +355,4 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)#define MBps (x) KBps(1000 * (x))#define GBps (x) ((u64)1000 * MBps((x))) -static inline const char *yesno (bool v) -{ -return v ?"yes" :"no" ; -} - -static inline const char *onoff (bool v) -{ -return v ?"on" :"off" ; -} - -static inline const char *enableddisabled (bool v) -{ -return v ?"enabled" :"disabled" ; -} -#endif /* !__I915_UTILS_H */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +0 -11
@@ -2023,17 +2023,6 @@ static const struct file_operations rss_debugfs_fops = {/* RSS Configuration. */ -/* Small utility function to return the strings "yes" or "no" if the supplied -* argument is non-zero. -*/ -static const char *yesno (int x) -{ -static const char *yes ="yes" ; -static const char *no ="no" ; - -return x ? yes : no; -} -static int rss_config_show (struct seq_file *seq,void *v) {struct adapter *adapter = seq->private;
drivers/usb/core/config.c +0 -5
@@ -19,11 +19,6 @@#define USB_MAXCONFIG 8/* Arbitrary limit */ -static inline const char *plural (int n) -{ -return (n ==1 ?"" :"s" ); -} -static int find_next_descriptor (unsigned char *buffer,int size,int dt1,int dt2,int *num_skipped) {
drivers/usb/core/generic.c +0 -5
@@ -24,11 +24,6 @@#include <uapi/linux/usb/audio.h> #include "usb.h" -static inline const char *plural (int n) -{ -return (n ==1 ?"" :"s" ); -} -static int is_rndis (struct usb_interface_descriptor *desc) {return desc->bInterfaceClass ==USB_CLASS_COMM
include/linux/kernel.h +21 -0
@@ -1008,4 +1008,25 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }/* OTHER_WRITABLE? Generally considered a bad idea. */ \ BUILD_BUG_ON_ZERO((perms) & 2) + \ (perms)) + +static inline const char *yesno (bool v) +{ +return v ?"yes" :"no" ; +} + +static inline const char *onoff (bool v) +{ +return v ?"on" :"off" ; +} + +static inline const char *enableddisabled (bool v) +{ +return v ?"enabled" :"disabled" ; +} + +static inline const char *plural (long v) +{ +return v ==1 ?"" :"s" ; +} +#endif
Signature · 1 line
2.20.1
PATCH 2/2 drm: convert to use yesno(), onoff(), enableddisabled(), plural() helpers
THIS IS NOT FOR MERGING; DEMO FOR PREVIOUS PATCH ONLY!
Further conversion should be done incrementally and by driver/subsystem. This here is the result of running the following on the below cocci patch:
$ spatch --sp-file yesno.cocci --in-place --dir drivers/gpu/drm
I wish I knew how to not duplicate stuff in the cocci patch so much...
@enableddisabled@
expression E;
@@
(
- (E) ? "enabled" : "disabled"
+ enableddisabled(E)
|
- E ? "enabled" : "disabled"
+ enableddisabled(E)
)
@reverse_enableddisabled@
expression A, B;
@@
(
- (A == B) ? "disabled" : "enabled"
+ enableddisabled(A != B)
|
- (A != B) ? "disabled" : "enabled"
+ enableddisabled(A == B)
|
- A == B ? "disabled" : "enabled"
+ enableddisabled(A != B)
|
- A != B ? "disabled" : "enabled"
+ enableddisabled(A == B)
|
- A ? "disabled" : "enabled"
+ enableddisabled(!A)
)
@yesno@
expression E;
@@
(
- (E) ? "yes" : "no"
+ yesno(E)
|
- E ? "yes" : "no"
+ yesno(E)
)
@reverse_yesno@
expression A, B;
@@
(
- (A == B) ? "no" : "yes"
+ yesno(A != B)
|
- (A != B) ? "no" : "yes"
+ yesno(A == B)
|
- A == B ? "no" : "yes"
+ yesno(A != B)
|
- A != B ? "no" : "yes"
+ yesno(A == B)
|
- A ? "no" : "yes"
+ yesno(!A)
)
@onoff@
expression E;
@@
(
- (E) ? "on" : "off"
+ onoff(E)
|
- E ? "on" : "off"
+ onoff(E)
)
@reverse_onoff@
expression A, B;
@@
(
- (A == B) ? "off" : "on"
+ onoff(A != B)
|
- (A != B) ? "off" : "on"
+ onoff(A == B)
|
- A == B ? "off" : "on"
+ onoff(A != B)
|
- A != B ? "off" : "on"
+ onoff(A == B)
|
- A ? "off" : "on"
+ onoff(!A)
)
@plural@
expression E;
@@
(
- (E > 1) ? "s" : ""
+ plural(E)
|
- E > 1 ? "s" : ""
+ plural(E)
|
- (E == 1) ? "" : "s"
+ plural(E)
|
- E == 1 ? "" : "s"
+ plural(E)
)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 2 +- drivers/gpu/drm/amd/amdgpu/atom.c | 2 +- drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c | 3 ++- drivers/gpu/drm/bridge/tc358767.c | 2 +- drivers/gpu/drm/drm_client_modeset.c | 2 +- drivers/gpu/drm/drm_dp_helper.c | 2 +- drivers/gpu/drm/drm_edid_load.c | 2 +- drivers/gpu/drm/drm_gem.c | 2 +- drivers/gpu/drm/i915/display/intel_display.c | 2 +- drivers/gpu/drm/nouveau/nouveau_acpi.c | 2 +- drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c | 2 +- drivers/gpu/drm/omapdrm/dss/dispc.c | 2 +- drivers/gpu/drm/omapdrm/dss/dsi.c | 6 ++---- drivers/gpu/drm/qxl/qxl_display.c | 2 +- drivers/gpu/drm/radeon/atom.c | 2 +- drivers/gpu/drm/radeon/radeon_acpi.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 4 ++-- drivers/gpu/drm/sti/sti_tvout.c | 2 +- drivers/gpu/drm/sun4i/sun4i_backend.c | 2 +- drivers/gpu/drm/sun4i/sun8i_ui_layer.c | 2 +- drivers/gpu/drm/v3d/v3d_debugfs.c | 10 +++++----- drivers/gpu/drm/virtio/virtgpu_debugfs.c | 2 +- 22 files changed, 29 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +1 -1
@@ -292,7 +292,7 @@ static int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif) out:DRM_DEBUG_DRIVER ("Notification %s, command code = %#x\n" , - (n->enabled ?"enabled" :"disabled" ), + (enableddisabled (n->enabled)), n->command_code);kfree (info);return err;
drivers/gpu/drm/amd/amdgpu/atom.c +1 -1
@@ -737,7 +737,7 @@ static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg)break ; }if (arg !=ATOM_COND_ALWAYS ) -SDEBUG (" taken: %s\n" , execute ?"yes" :"no" ); +SDEBUG (" taken: %s\n" ,yesno (execute));SDEBUG (" target: 0x%04X\n" , target);if (execute) {if (ctx->last_jump == (ctx->start + target)) {
drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c +2 -1
@@ -2918,7 +2918,8 @@ static int vega10_enable_disable_PCC_limit_feature(struct pp_hwmgr *hwmgr, boolif (data->smu_features[GNLD_PCC_LIMIT ].supported) {if (enable == data->smu_features[GNLD_PCC_LIMIT ].enabled) -pr_info ("GNLD_PCC_LIMIT has been %s \n" , enable ?"enabled" :"disabled" ); +pr_info ("GNLD_PCC_LIMIT has been %s \n" , +enableddisabled (enable)); PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr, enable, data->smu_features[GNLD_PCC_LIMIT].smu_feature_bitmap), "Attempt to Enable PCC Limit feature Failed!",
drivers/gpu/drm/bridge/tc358767.c +1 -1
@@ -653,7 +653,7 @@ static int tc_get_display_props(struct tc_data *tc) "enhanced" : "non-enhanced"); dev_dbg(tc->dev,"Downspread: %s, scrambler: %s\n" , tc->link.spread ?"0.5%" :"0.0%" , - tc->link.scrambler_dis ?"disabled" :"enabled" ); +enableddisabled (!tc->link.scrambler_dis));dev_dbg (tc->dev,"Display ASSR: %d, TC358767 ASSR: %d\n" , tc->link.assr, tc->assr);
drivers/gpu/drm/drm_client_modeset.c +1 -1
@@ -213,7 +213,7 @@ static void drm_client_connectors_enabled(struct drm_connector **connectors, connector = connectors[i]; enabled[i] =drm_connector_enabled (connector, true);DRM_DEBUG_KMS ("connector %d enabled? %s\n" , connector->base.id, - connector->display_info.non_desktop ?"non desktop" : enabled[i] ?"yes" :"no" ); + connector->display_info.non_desktop ?"non desktop" :yesno (enabled[i])); any_enabled |= enabled[i]; }
drivers/gpu/drm/drm_dp_helper.c +1 -1
@@ -600,7 +600,7 @@ void drm_dp_downstream_debug(struct seq_file *m,DP_DWN_STRM_PORT_PRESENT ;seq_printf (m,"\tDP branch device present: %s\n" , - branch_device ?"yes" :"no" ); +yesno (branch_device));if (!branch_device)return ;
drivers/gpu/drm/drm_edid_load.c +1 -1
@@ -255,7 +255,7 @@ static void *edid_load(struct drm_connector *connector, const char *name,DRM_INFO ("Got %s EDID base block and %d extension%s from " "\"%s\" for connector \"%s\"\n" , (builtin >=0 ) ?"built-in" : -"external" , valid_extensions, valid_extensions ==1 ?"" :"s" , +"external" , valid_extensions,plural (valid_extensions), name, connector_name); out:
drivers/gpu/drm/drm_gem.c +1 -1
@@ -1208,7 +1208,7 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent, drm_vma_node_start(&obj->vma_node));drm_printf_indent (p, indent,"size=%zu\n" , obj->size);drm_printf_indent (p, indent,"imported=%s\n" , - obj->import_attach ?"yes" :"no" ); +yesno (obj->import_attach));if (obj->funcs && obj->funcs->print_info) obj->funcs->print_info (p, indent, obj);
drivers/gpu/drm/i915/display/intel_display.c +1 -1
@@ -16006,7 +16006,7 @@ int intel_modeset_init(struct drm_device *dev)DRM_DEBUG_KMS ("%d display pipe%s available.\n" ,INTEL_INFO (dev_priv)->num_pipes, -INTEL_INFO (dev_priv)->num_pipes >1 ?"s" :"" ); +plural (INTEL_INFO (dev_priv)->num_pipes));for_each_pipe (dev_priv, pipe) { ret =intel_crtc_init (dev_priv, pipe);
drivers/gpu/drm/nouveau/nouveau_acpi.c +1 -1
@@ -277,7 +277,7 @@ static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_outnouveau_optimus_dsm (dhandle,NOUVEAU_DSM_OPTIMUS_CAPS ,0 , &result);dev_info (&pdev->dev,"optimus capabilities: %s, status %s%s\n" , - (result &OPTIMUS_ENABLED ) ?"enabled" :"disabled" , +enableddisabled (result &OPTIMUS_ENABLED ), (result &OPTIMUS_DYNAMIC_PWR_CAP ) ?"dynamic power, " :"" , (result &OPTIMUS_HDA_CODEC_MASK ) ?"hda bios codec supported" :"" );
drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c +1 -1
@@ -94,7 +94,7 @@ void nvkm_i2c_aux_monitor(struct nvkm_i2c_aux *aux, bool monitor) {struct nvkm_i2c_pad *pad = aux->pad; -AUX_TRACE (aux,"monitor: %s" , monitor ?"yes" :"no" ); +AUX_TRACE (aux,"monitor: %s" ,yesno (monitor));if (monitor)nvkm_i2c_pad_mode (pad,NVKM_I2C_PAD_AUX );else
drivers/gpu/drm/omapdrm/dss/dispc.c +1 -1
@@ -1506,7 +1506,7 @@ void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)return ; } -DSSDBG ("FIFO merge %s\n" , enable ?"enabled" :"disabled" ); +DSSDBG ("FIFO merge %s\n" ,enableddisabled (enable));REG_FLD_MOD (dispc,DISPC_CONFIG , enable ?1 :0 ,14 ,14 ); }
drivers/gpu/drm/omapdrm/dss/dsi.c +2 -4
@@ -1408,8 +1408,7 @@ static int dsi_dump_dsi_clocks(struct seq_file *s, void *p) DSS_CLK_SRC_PLL2_1), cinfo->clkout[HSDIV_DISPC ], cinfo->mX[HSDIV_DISPC ], - dispc_clk_src ==DSS_CLK_SRC_FCK ? - "off" : "on"); + onoff(dispc_clk_src != DSS_CLK_SRC_FCK)); seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16lum_dsi %u\t(%s)\n", dss_get_clk_source_name(dsi_module == 0 ?
@@ -1417,8 +1416,7 @@ static int dsi_dump_dsi_clocks(struct seq_file *s, void *p) DSS_CLK_SRC_PLL2_2), cinfo->clkout[HSDIV_DSI ], cinfo->mX[HSDIV_DSI ], - dsi_clk_src ==DSS_CLK_SRC_FCK ? - "off" : "on"); + onoff(dsi_clk_src != DSS_CLK_SRC_FCK));seq_printf (s,"- DSI%d -\n" , dsi_module +1 );
drivers/gpu/drm/qxl/qxl_display.c +1 -1
@@ -355,7 +355,7 @@ static void qxl_crtc_update_monitors_config(struct drm_crtc *crtc,DRM_DEBUG_KMS ("head %d, %dx%d, at +%d+%d, %s (%s)\n" , i, head.width, head.height, head.x, head.y, - crtc->state->active ?"on" :"off" , reason); +onoff (crtc->state->active), reason);if (oldcount != qdev->monitors_config->count) DRM_DEBUG_KMS("active heads %d -> %d (%d total)\n", oldcount, qdev->monitors_config->count,
drivers/gpu/drm/radeon/atom.c +1 -1
@@ -722,7 +722,7 @@ static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg)break ; }if (arg !=ATOM_COND_ALWAYS ) -SDEBUG (" taken: %s\n" , execute ?"yes" :"no" ); +SDEBUG (" taken: %s\n" ,yesno (execute));SDEBUG (" target: 0x%04X\n" , target);if (execute) {if (ctx->last_jump == (ctx->start + target)) {
drivers/gpu/drm/radeon/radeon_acpi.c +1 -1
@@ -299,7 +299,7 @@ static int radeon_atif_get_notification_params(acpi_handle handle, out:DRM_DEBUG_DRIVER ("Notification %s, command code = %#x\n" , - (n->enabled ?"enabled" :"disabled" ), + (enableddisabled (n->enabled)), n->command_code);kfree (info);return err;
drivers/gpu/drm/sti/sti_hda.c +2 -2
@@ -317,7 +317,7 @@ static void hda_enable_hd_dacs(struct sti_hda *hda, bool enable)static void hda_dbg_cfg (struct seq_file *s,int val) {seq_puts (s,"\tAWG " ); -seq_puts (s, val &CFG_AWG_ASYNC_EN ?"enabled" :"disabled" ); +seq_puts (s,enableddisabled (val &CFG_AWG_ASYNC_EN )); }static void hda_dbg_awg_microcode (struct seq_file *s,void __iomem *reg)
@@ -338,7 +338,7 @@ static void hda_dbg_video_dacs_ctrl(struct seq_file *s, void __iomem *reg)seq_printf (s,"\n\n %-25s 0x%08X" ,"VIDEO_DACS_CONTROL" , val);seq_puts (s,"\tHD DACs " ); -seq_puts (s, val &DAC_CFG_HD_HZUVW_OFF_MASK ?"disabled" :"enabled" ); +seq_puts (s,enableddisabled (!(val &DAC_CFG_HD_HZUVW_OFF_MASK ))); }static int hda_dbg_show (struct seq_file *s,void *data)
drivers/gpu/drm/sti/sti_tvout.c +1 -1
@@ -491,7 +491,7 @@ static void tvout_dbg_vip(struct seq_file *s, int val)static void tvout_dbg_hd_dac_cfg (struct seq_file *s,int val) {seq_printf (s,"\t%-24s %s" ,"HD DAC:" , - val &1 ?"disabled" :"enabled" ); +enableddisabled (!(val &1 ))); }static int tvout_dbg_show (struct seq_file *s,void *data)
drivers/gpu/drm/sun4i/sun4i_backend.c +1 -1
@@ -273,7 +273,7 @@ int sun4i_backend_update_layer_formats(struct sun4i_backend *backend, interlaced ? SUN4I_BACKEND_MODCTL_ITLMOD_EN : 0);DRM_DEBUG_DRIVER ("Switching display backend interlaced mode %s\n" , - interlaced ?"on" :"off" ); +onoff (interlaced)); val =SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA (state->alpha >>8 );if (state->alpha !=DRM_BLEND_ALPHA_OPAQUE )
drivers/gpu/drm/sun4i/sun8i_ui_layer.c +1 -1
@@ -126,7 +126,7 @@ static int sun8i_ui_layer_update_coord(struct sun8i_mixer *mixer, int channel, val);DRM_DEBUG_DRIVER ("Switching display mixer interlaced mode %s\n" , - interlaced ?"on" :"off" ); +onoff (interlaced)); }/* Set height and width */
drivers/gpu/drm/v3d/v3d_debugfs.c +5 -5
@@ -147,15 +147,15 @@ static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)V3D_GET_FIELD (ident3,V3D_HUB_IDENT3_IPREV ), V3D_GET_FIELD(ident3, V3D_HUB_IDENT3_IPIDX));seq_printf (m,"MMU: %s\n" , - (ident2 &V3D_HUB_IDENT2_WITH_MMU ) ?"yes" :"no" ); +yesno (ident2 &V3D_HUB_IDENT2_WITH_MMU ));seq_printf (m,"TFU: %s\n" , - (ident1 &V3D_HUB_IDENT1_WITH_TFU ) ?"yes" :"no" ); +yesno (ident1 &V3D_HUB_IDENT1_WITH_TFU ));seq_printf (m,"TSY: %s\n" , - (ident1 &V3D_HUB_IDENT1_WITH_TSY ) ?"yes" :"no" ); +yesno (ident1 &V3D_HUB_IDENT1_WITH_TSY ));seq_printf (m,"MSO: %s\n" , - (ident1 &V3D_HUB_IDENT1_WITH_MSO ) ?"yes" :"no" ); +yesno (ident1 &V3D_HUB_IDENT1_WITH_MSO ));seq_printf (m,"L3C: %s (%dkb)\n" , - (ident1 &V3D_HUB_IDENT1_WITH_L3C ) ?"yes" :"no" , +yesno (ident1 &V3D_HUB_IDENT1_WITH_L3C ),V3D_GET_FIELD (ident2,V3D_HUB_IDENT2_L3C_NKB ));for (core =0 ; core < cores; core++) {
drivers/gpu/drm/virtio/virtgpu_debugfs.c +1 -1
@@ -31,7 +31,7 @@static void virtio_add_bool (struct seq_file *m,const char *name,bool value) { -seq_printf (m,"%-16s : %s\n" , name, value ?"yes" :"no" ); +seq_printf (m,"%-16s : %s\n" , name,yesno (value)); } static void virtio_add_int(struct seq_file *m, const char *name,
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BUILD: failure for series starting with [1/2] linux/kernel.h: add yesno(), onoff(), enableddisabled(), plural() helpers
In reply to Jani Nikula== Series Details ==
== Series Details ==
Series: series starting with [1/2] linux/kernel.h: add yesno(), onoff(), enableddisabled(), plural() helpers
URL : https://patchwork.freedesktop.org/series/66170/
State : failure
== Summary ==
Applying: linux/kernel.h: add yesno(), onoff(), enableddisabled(), plural() helpers Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/i915_utils.h
Falling back to patching base and 3-way merge...
Auto-merging drivers/gpu/drm/i915/i915_utils.h
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/i915_utils.h
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at 0001 linux/kernel.h: add yesno(), onoff(), enableddisabled(), plural() helpers When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 36 lines · Jani Nikula
The kernel has plenty of ternary operators to choose between constant strings, such as condition ? "yes" : "no", as well as value == 1 ? "" :
"s":$ git grep '? "yes" : "no"' | wc -l 258 $ git grep '? "on" : "off"' | wc -l 204 $ git grep '? "enabled" : "disabled"' | wc -l 196 $ git grep '? "" : "s"' | wc -l 25Additionally, there are some occurences of the same in reverse order, split to multiple lines, or otherwise not caught by the simple grep.
Add helpers to return the constant strings. Remove existing equivalent and conflicting functions in i915, cxgb4, and USB core. Further conversion can be done incrementally.
While the main goal here is to abstract recurring patterns, and slightly clean up the code base by not open coding the ternary operators, there are also some space savings to be had via better string constant pooling.
Cc Joonas Lahtinen <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc Vishal Kulkarni <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Andrew Morton <[email protected]>Cc Julia Lawall <[email protected]>Signed-off-by Jani Nikula <[email protected]>
Quoted 7 lines
--- drivers/gpu/drm/i915/i915_utils.h | 15 ------------- .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 11 ---------- drivers/usb/core/config.c | 5 ----- drivers/usb/core/generic.c | 5 ----- include/linux/kernel.h | 21 +++++++++++++++++++ 5 files changed, 21 insertions(+), 36 deletions(-)
Quoted 4 lines · Jani Nikula
While the main goal here is to abstract recurring patterns, and slightly clean up the code base by not open coding the ternary operators, there are also some space savings to be had via better string constant pooling.
Eh, no? The linker does that across translation units anyway - moreover, given that you make them static inlines, "yes" and "no" will still live in .rodata.strX.Y in each individual TU that uses the yesno() helper.
The enableddisabled() is a mouthful, perhaps the helpers should have an underscore between the choices
yes_no()enabled_disabled()on_off()
?
Quoted 5 lines
drivers/gpu/drm/i915/i915_utils.h | 15 ------------- .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 11 ---------- drivers/usb/core/config.c | 5 ----- drivers/usb/core/generic.c | 5 ----- include/linux/kernel.h | 21 +++++++++++++++++++
Pet peeve: Can we please stop using linux/kernel.h as a dumping ground for every little utility/helper? That makes each and every translation unit in the kernel slightly larger, hence slower to compile. Please make a linux/string-choice.h and put them there.
Rasmus
Quoted 10 lines · Rasmus Villemoes
Quoted 4 lines · Jani Nikula
While the main goal here is to abstract recurring patterns, and slightly clean up the code base by not open coding the ternary operators, there are also some space savings to be had via better string constant pooling.
Eh, no? The linker does that across translation units anyway - moreover, given that you make them static inlines, "yes" and "no" will still live in .rodata.strX.Y in each individual TU that uses the
yesno()helper.
I should've been more careful there; this allows us to do better constant pooling but does not actually deliver on that here. You'd need to return pointers to strings in the kernel image. The linker can't constant pool across modules by itself.
Anyway, that was not the main point here.
Quoted 8 lines
The
enableddisabled()is a mouthful, perhaps the helpers should have an underscore between the choices
yes_no()enabled_disabled()on_off()?
I'm replacing existing functions that are being used in the kernel already.
$ git grep "[^a-zA-Z0-9_]\(yesno\|onoff\|enableddisabled\)(" | wc -l
241Not keen on renaming all of them.
Quoted 10 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_utils.h | 15 ------------- .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 11 ---------- drivers/usb/core/config.c | 5 ----- drivers/usb/core/generic.c | 5 ----- include/linux/kernel.h | 21 +++++++++++++++++++Pet peeve: Can we please stop using
linux/kernel.has a dumping ground for every little utility/helper? That makes each and every translation unit in the kernel slightly larger, hence slower to compile. Please make alinux/string-choice.hand put them there.
*grin*
In the absense of a natural candidate in include/linux/*.h, I thought shoving them to kernel.h would provoke the best feedback on where to put them. A new string-choice.h works for me, thanks. :)
BR,
Jani.
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center