Skip to contentSkip to conversation

Fixing indentation for a generated patch?

cocci Markus Elfring 1 participant 1 message Apr 2, 2025

lore
Share & tools
lore
#0 lore raw

Hello,

I noticed during a patch review that a specific source code place contains the opportunity for another bit of simplification.

Example:
avs_component_probe()
https://elixir.bootlin.com/linux/v6.14-rc6/source/sound/soc/intel/avs/pcm.c#L924-L929

I constructed a script variant (like the following) for the semantic patch language.

@replacement disable drop_else, neg_if@ constant char[] text1, text2;
expression action, check, target; expression list inputs;
@@
-if (check)
- target = action(inputs, text1);
-else
- target = action(inputs, text2);
+target = action(inputs, (check) ? text1 : text2);

I find a corresponding test result (from the software combination “Coccinelle 1.3-00083-g4093aad2d”) questionable according to known coding style requirements for Linux development.

Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time spatch …/Projekte/Coccinelle/janitor/use_ternary_operator7.cocci sound/soc/intel/avs/pcm.c …
@@ -921,12 +921,8 @@ static int avs_component_probe(struct sn
…
+ mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
+ (((vendor_id >> 16) & 0xFFFF) == 0x8086) ? "hda-8086-generic-tplg.bin" : "hda-generic-tplg.bin");

                filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
                                     mach->tplg_filename);
real    0m0,513s
user    0m0,454s
sys     0m0,057s

How can more appropriate indentation (including tab characters) be achieved here automatically?

Regards,
Markus