[PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2

songxiebing posted 1 patch 1 week, 4 days ago
There is a newer version of this series
sound/core/seq/seq_ump_convert.c | 33 ++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
[PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
Posted by songxiebing 1 week, 4 days ago
There are multiple early return branches within the func, and compiler
optimizations(such as -O2/-O3)lead to abnormal stack frame analysis -
objtool cannot comfirm that the stack frames of all branches can be
correctly restored, thus generating false warnings.

Below:
>> sound/core/seq/seq_ump_convert.o: warning: objtool: cc_ev_to_ump_midi2+0x589: return with modified stack frame

So we modify it by uniformly returning at the and of the function.

Signed-off-by: songxiebing <songxiebing@kylinos.cn>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202503200535.J3hAvcjw-lkp@intel.com/
---
 sound/core/seq/seq_ump_convert.c | 33 ++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/sound/core/seq/seq_ump_convert.c b/sound/core/seq/seq_ump_convert.c
index db2f169cae11..cebc92e7baa0 100644
--- a/sound/core/seq/seq_ump_convert.c
+++ b/sound/core/seq/seq_ump_convert.c
@@ -841,7 +841,7 @@ static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
 	unsigned char index = event->data.control.param & 0x7f;
 	unsigned char val = event->data.control.value & 0x7f;
 	struct ump_cvt_to_ump_bank *cc = &dest_port->midi2_bank[channel];
-	int ret;
+	int ret = 0;
 
 	/* process special CC's (bank/rpn/nrpn) */
 	switch (index) {
@@ -851,47 +851,52 @@ static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
 		cc->cc_rpn_msb = val;
 		if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
 			reset_rpn(cc);
-		return ret;
+		break;
 	case UMP_CC_RPN_LSB:
 		ret = fill_rpn(cc, data, channel, true);
 		cc->rpn_set = 1;
 		cc->cc_rpn_lsb = val;
 		if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
 			reset_rpn(cc);
-		return ret;
+		break;
 	case UMP_CC_NRPN_MSB:
 		ret = fill_rpn(cc, data, channel, true);
 		cc->nrpn_set = 1;
 		cc->cc_nrpn_msb = val;
-		return ret;
+		break;
 	case UMP_CC_NRPN_LSB:
 		ret = fill_rpn(cc, data, channel, true);
 		cc->nrpn_set = 1;
 		cc->cc_nrpn_lsb = val;
-		return ret;
+		break;
 	case UMP_CC_DATA:
 		cc->cc_data_msb_set = 1;
 		cc->cc_data_msb = val;
-		return fill_rpn(cc, data, channel, false);
+		ret = fill_rpn(cc, data, channel, false);
+		break;
 	case UMP_CC_BANK_SELECT:
 		cc->bank_set = 1;
 		cc->cc_bank_msb = val;
-		return 0; // skip
+		ret = 0; // skip
 	case UMP_CC_BANK_SELECT_LSB:
 		cc->bank_set = 1;
 		cc->cc_bank_lsb = val;
-		return 0; // skip
+		ret = 0; // skip
 	case UMP_CC_DATA_LSB:
 		cc->cc_data_lsb_set = 1;
 		cc->cc_data_lsb = val;
-		return fill_rpn(cc, data, channel, false);
+		ret = fill_rpn(cc, data, channel, false);
+		break;
+	default:
+		data->cc.status = status;
+		data->cc.channel = channel;
+		data->cc.index = index;
+		data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
+		ret = 1;
+		break;
 	}
 
-	data->cc.status = status;
-	data->cc.channel = channel;
-	data->cc.index = index;
-	data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
-	return 1;
+	return ret;
 }
 
 /* convert one-parameter control event to MIDI 2.0 UMP */
-- 
2.25.1
Re: [PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
Posted by kernel test robot 1 week, 3 days ago
Hi songxiebing,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on tiwai-sound/for-linus linus/master v7.0-rc5 next-20260323]
[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/songxiebing/ALSA-core-seq-Optimize-the-return-logic-in-cc_ev_to_ump_midi2/20260324-013342
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20260323024742.220707-1-songxiebing%40kylinos.cn
patch subject: [PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260324/202603240812.jjlE0H3s-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260324/202603240812.jjlE0H3s-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603240812.jjlE0H3s-lkp@intel.com/

All warnings (new ones prefixed by >>):

   sound/core/seq/seq_ump_convert.c: In function 'cc_ev_to_ump_midi2':
>> sound/core/seq/seq_ump_convert.c:880:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
     880 |                 ret = 0; // skip
         |                 ~~~~^~~
   sound/core/seq/seq_ump_convert.c:881:9: note: here
     881 |         case UMP_CC_BANK_SELECT_LSB:
         |         ^~~~
   sound/core/seq/seq_ump_convert.c:884:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
     884 |                 ret = 0; // skip
         |                 ~~~~^~~
   sound/core/seq/seq_ump_convert.c:885:9: note: here
     885 |         case UMP_CC_DATA_LSB:
         |         ^~~~


vim +880 sound/core/seq/seq_ump_convert.c

   833	
   834	/* convert CC event to MIDI 2.0 UMP */
   835	static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
   836				      struct snd_seq_client_port *dest_port,
   837				      union snd_ump_midi2_msg *data,
   838				      unsigned char status)
   839	{
   840		unsigned char channel = event->data.control.channel & 0x0f;
   841		unsigned char index = event->data.control.param & 0x7f;
   842		unsigned char val = event->data.control.value & 0x7f;
   843		struct ump_cvt_to_ump_bank *cc = &dest_port->midi2_bank[channel];
   844		int ret = 0;
   845	
   846		/* process special CC's (bank/rpn/nrpn) */
   847		switch (index) {
   848		case UMP_CC_RPN_MSB:
   849			ret = fill_rpn(cc, data, channel, true);
   850			cc->rpn_set = 1;
   851			cc->cc_rpn_msb = val;
   852			if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
   853				reset_rpn(cc);
   854			break;
   855		case UMP_CC_RPN_LSB:
   856			ret = fill_rpn(cc, data, channel, true);
   857			cc->rpn_set = 1;
   858			cc->cc_rpn_lsb = val;
   859			if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
   860				reset_rpn(cc);
   861			break;
   862		case UMP_CC_NRPN_MSB:
   863			ret = fill_rpn(cc, data, channel, true);
   864			cc->nrpn_set = 1;
   865			cc->cc_nrpn_msb = val;
   866			break;
   867		case UMP_CC_NRPN_LSB:
   868			ret = fill_rpn(cc, data, channel, true);
   869			cc->nrpn_set = 1;
   870			cc->cc_nrpn_lsb = val;
   871			break;
   872		case UMP_CC_DATA:
   873			cc->cc_data_msb_set = 1;
   874			cc->cc_data_msb = val;
   875			ret = fill_rpn(cc, data, channel, false);
   876			break;
   877		case UMP_CC_BANK_SELECT:
   878			cc->bank_set = 1;
   879			cc->cc_bank_msb = val;
 > 880			ret = 0; // skip
   881		case UMP_CC_BANK_SELECT_LSB:
   882			cc->bank_set = 1;
   883			cc->cc_bank_lsb = val;
   884			ret = 0; // skip
   885		case UMP_CC_DATA_LSB:
   886			cc->cc_data_lsb_set = 1;
   887			cc->cc_data_lsb = val;
   888			ret = fill_rpn(cc, data, channel, false);
   889			break;
   890		default:
   891			data->cc.status = status;
   892			data->cc.channel = channel;
   893			data->cc.index = index;
   894			data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
   895			ret = 1;
   896			break;
   897		}
   898	
   899		return ret;
   900	}
   901	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
Posted by kernel test robot 1 week, 3 days ago
Hi songxiebing,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on tiwai-sound/for-linus linus/master v7.0-rc5 next-20260323]
[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/songxiebing/ALSA-core-seq-Optimize-the-return-logic-in-cc_ev_to_ump_midi2/20260324-013342
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20260323024742.220707-1-songxiebing%40kylinos.cn
patch subject: [PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20260324/202603241242.5Kms3LqO-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260324/202603241242.5Kms3LqO-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603241242.5Kms3LqO-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> sound/core/seq/seq_ump_convert.c:881:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
     881 |         case UMP_CC_BANK_SELECT_LSB:
         |         ^
   sound/core/seq/seq_ump_convert.c:881:2: note: insert '__attribute__((fallthrough));' to silence this warning
     881 |         case UMP_CC_BANK_SELECT_LSB:
         |         ^
         |         __attribute__((fallthrough)); 
   sound/core/seq/seq_ump_convert.c:881:2: note: insert 'break;' to avoid fall-through
     881 |         case UMP_CC_BANK_SELECT_LSB:
         |         ^
         |         break; 
   sound/core/seq/seq_ump_convert.c:885:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
     885 |         case UMP_CC_DATA_LSB:
         |         ^
   sound/core/seq/seq_ump_convert.c:885:2: note: insert '__attribute__((fallthrough));' to silence this warning
     885 |         case UMP_CC_DATA_LSB:
         |         ^
         |         __attribute__((fallthrough)); 
   sound/core/seq/seq_ump_convert.c:885:2: note: insert 'break;' to avoid fall-through
     885 |         case UMP_CC_DATA_LSB:
         |         ^
         |         break; 
   2 warnings generated.


vim +881 sound/core/seq/seq_ump_convert.c

e9e02819a98a50 Takashi Iwai 2023-05-23  833  
e9e02819a98a50 Takashi Iwai 2023-05-23  834  /* convert CC event to MIDI 2.0 UMP */
e9e02819a98a50 Takashi Iwai 2023-05-23  835  static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
e9e02819a98a50 Takashi Iwai 2023-05-23  836  			      struct snd_seq_client_port *dest_port,
e9e02819a98a50 Takashi Iwai 2023-05-23  837  			      union snd_ump_midi2_msg *data,
e9e02819a98a50 Takashi Iwai 2023-05-23  838  			      unsigned char status)
e9e02819a98a50 Takashi Iwai 2023-05-23  839  {
e9e02819a98a50 Takashi Iwai 2023-05-23  840  	unsigned char channel = event->data.control.channel & 0x0f;
e9e02819a98a50 Takashi Iwai 2023-05-23  841  	unsigned char index = event->data.control.param & 0x7f;
e9e02819a98a50 Takashi Iwai 2023-05-23  842  	unsigned char val = event->data.control.value & 0x7f;
a683030606fa5f Takashi Iwai 2024-07-31  843  	struct ump_cvt_to_ump_bank *cc = &dest_port->midi2_bank[channel];
521be8ec43cb74 songxiebing  2026-03-23  844  	int ret = 0;
e9e02819a98a50 Takashi Iwai 2023-05-23  845  
e9e02819a98a50 Takashi Iwai 2023-05-23  846  	/* process special CC's (bank/rpn/nrpn) */
e9e02819a98a50 Takashi Iwai 2023-05-23  847  	switch (index) {
e9e02819a98a50 Takashi Iwai 2023-05-23  848  	case UMP_CC_RPN_MSB:
a4ff92ff0bdd73 Takashi Iwai 2024-07-31  849  		ret = fill_rpn(cc, data, channel, true);
e9e02819a98a50 Takashi Iwai 2023-05-23  850  		cc->rpn_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  851  		cc->cc_rpn_msb = val;
98ea612dd1150a Takashi Iwai 2024-07-31  852  		if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
98ea612dd1150a Takashi Iwai 2024-07-31  853  			reset_rpn(cc);
521be8ec43cb74 songxiebing  2026-03-23  854  		break;
e9e02819a98a50 Takashi Iwai 2023-05-23  855  	case UMP_CC_RPN_LSB:
a4ff92ff0bdd73 Takashi Iwai 2024-07-31  856  		ret = fill_rpn(cc, data, channel, true);
e9e02819a98a50 Takashi Iwai 2023-05-23  857  		cc->rpn_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  858  		cc->cc_rpn_lsb = val;
98ea612dd1150a Takashi Iwai 2024-07-31  859  		if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
98ea612dd1150a Takashi Iwai 2024-07-31  860  			reset_rpn(cc);
521be8ec43cb74 songxiebing  2026-03-23  861  		break;
e9e02819a98a50 Takashi Iwai 2023-05-23  862  	case UMP_CC_NRPN_MSB:
a4ff92ff0bdd73 Takashi Iwai 2024-07-31  863  		ret = fill_rpn(cc, data, channel, true);
e9e02819a98a50 Takashi Iwai 2023-05-23  864  		cc->nrpn_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  865  		cc->cc_nrpn_msb = val;
521be8ec43cb74 songxiebing  2026-03-23  866  		break;
e9e02819a98a50 Takashi Iwai 2023-05-23  867  	case UMP_CC_NRPN_LSB:
a4ff92ff0bdd73 Takashi Iwai 2024-07-31  868  		ret = fill_rpn(cc, data, channel, true);
e9e02819a98a50 Takashi Iwai 2023-05-23  869  		cc->nrpn_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  870  		cc->cc_nrpn_lsb = val;
521be8ec43cb74 songxiebing  2026-03-23  871  		break;
e9e02819a98a50 Takashi Iwai 2023-05-23  872  	case UMP_CC_DATA:
a4ff92ff0bdd73 Takashi Iwai 2024-07-31  873  		cc->cc_data_msb_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  874  		cc->cc_data_msb = val;
521be8ec43cb74 songxiebing  2026-03-23  875  		ret = fill_rpn(cc, data, channel, false);
521be8ec43cb74 songxiebing  2026-03-23  876  		break;
e9e02819a98a50 Takashi Iwai 2023-05-23  877  	case UMP_CC_BANK_SELECT:
e9e02819a98a50 Takashi Iwai 2023-05-23  878  		cc->bank_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  879  		cc->cc_bank_msb = val;
521be8ec43cb74 songxiebing  2026-03-23  880  		ret = 0; // skip
e9e02819a98a50 Takashi Iwai 2023-05-23 @881  	case UMP_CC_BANK_SELECT_LSB:
e9e02819a98a50 Takashi Iwai 2023-05-23  882  		cc->bank_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  883  		cc->cc_bank_lsb = val;
521be8ec43cb74 songxiebing  2026-03-23  884  		ret = 0; // skip
e9e02819a98a50 Takashi Iwai 2023-05-23  885  	case UMP_CC_DATA_LSB:
a4ff92ff0bdd73 Takashi Iwai 2024-07-31  886  		cc->cc_data_lsb_set = 1;
e9e02819a98a50 Takashi Iwai 2023-05-23  887  		cc->cc_data_lsb = val;
521be8ec43cb74 songxiebing  2026-03-23  888  		ret = fill_rpn(cc, data, channel, false);
521be8ec43cb74 songxiebing  2026-03-23  889  		break;
521be8ec43cb74 songxiebing  2026-03-23  890  	default:
e9e02819a98a50 Takashi Iwai 2023-05-23  891  		data->cc.status = status;
e9e02819a98a50 Takashi Iwai 2023-05-23  892  		data->cc.channel = channel;
e9e02819a98a50 Takashi Iwai 2023-05-23  893  		data->cc.index = index;
e9e02819a98a50 Takashi Iwai 2023-05-23  894  		data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
521be8ec43cb74 songxiebing  2026-03-23  895  		ret = 1;
521be8ec43cb74 songxiebing  2026-03-23  896  		break;
521be8ec43cb74 songxiebing  2026-03-23  897  	}
521be8ec43cb74 songxiebing  2026-03-23  898  
521be8ec43cb74 songxiebing  2026-03-23  899  	return ret;
e9e02819a98a50 Takashi Iwai 2023-05-23  900  }
e9e02819a98a50 Takashi Iwai 2023-05-23  901  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
Posted by kernel test robot 1 week, 3 days ago
Hi songxiebing,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on tiwai-sound/for-linus linus/master v7.0-rc5 next-20260323]
[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/songxiebing/ALSA-core-seq-Optimize-the-return-logic-in-cc_ev_to_ump_midi2/20260324-013342
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20260323024742.220707-1-songxiebing%40kylinos.cn
patch subject: [PATCH] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
config: arc-randconfig-002-20260324 (https://download.01.org/0day-ci/archive/20260324/202603240928.I9EN2k7j-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260324/202603240928.I9EN2k7j-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603240928.I9EN2k7j-lkp@intel.com/

All warnings (new ones prefixed by >>):

   sound/core/seq/seq_ump_convert.c: In function 'cc_ev_to_ump_midi2':
>> sound/core/seq/seq_ump_convert.c:880:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      ret = 0; // skip
      ~~~~^~~
   sound/core/seq/seq_ump_convert.c:881:2: note: here
     case UMP_CC_BANK_SELECT_LSB:
     ^~~~
   sound/core/seq/seq_ump_convert.c:884:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      ret = 0; // skip
      ~~~~^~~
   sound/core/seq/seq_ump_convert.c:885:2: note: here
     case UMP_CC_DATA_LSB:
     ^~~~


vim +880 sound/core/seq/seq_ump_convert.c

   833	
   834	/* convert CC event to MIDI 2.0 UMP */
   835	static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
   836				      struct snd_seq_client_port *dest_port,
   837				      union snd_ump_midi2_msg *data,
   838				      unsigned char status)
   839	{
   840		unsigned char channel = event->data.control.channel & 0x0f;
   841		unsigned char index = event->data.control.param & 0x7f;
   842		unsigned char val = event->data.control.value & 0x7f;
   843		struct ump_cvt_to_ump_bank *cc = &dest_port->midi2_bank[channel];
   844		int ret = 0;
   845	
   846		/* process special CC's (bank/rpn/nrpn) */
   847		switch (index) {
   848		case UMP_CC_RPN_MSB:
   849			ret = fill_rpn(cc, data, channel, true);
   850			cc->rpn_set = 1;
   851			cc->cc_rpn_msb = val;
   852			if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
   853				reset_rpn(cc);
   854			break;
   855		case UMP_CC_RPN_LSB:
   856			ret = fill_rpn(cc, data, channel, true);
   857			cc->rpn_set = 1;
   858			cc->cc_rpn_lsb = val;
   859			if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
   860				reset_rpn(cc);
   861			break;
   862		case UMP_CC_NRPN_MSB:
   863			ret = fill_rpn(cc, data, channel, true);
   864			cc->nrpn_set = 1;
   865			cc->cc_nrpn_msb = val;
   866			break;
   867		case UMP_CC_NRPN_LSB:
   868			ret = fill_rpn(cc, data, channel, true);
   869			cc->nrpn_set = 1;
   870			cc->cc_nrpn_lsb = val;
   871			break;
   872		case UMP_CC_DATA:
   873			cc->cc_data_msb_set = 1;
   874			cc->cc_data_msb = val;
   875			ret = fill_rpn(cc, data, channel, false);
   876			break;
   877		case UMP_CC_BANK_SELECT:
   878			cc->bank_set = 1;
   879			cc->cc_bank_msb = val;
 > 880			ret = 0; // skip
   881		case UMP_CC_BANK_SELECT_LSB:
   882			cc->bank_set = 1;
   883			cc->cc_bank_lsb = val;
   884			ret = 0; // skip
   885		case UMP_CC_DATA_LSB:
   886			cc->cc_data_lsb_set = 1;
   887			cc->cc_data_lsb = val;
   888			ret = fill_rpn(cc, data, channel, false);
   889			break;
   890		default:
   891			data->cc.status = status;
   892			data->cc.channel = channel;
   893			data->cc.index = index;
   894			data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
   895			ret = 1;
   896			break;
   897		}
   898	
   899		return ret;
   900	}
   901	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
[PATCH v2] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
Posted by songxiebing 1 week, 2 days ago
There are multiple early return branches within the func, and compiler
optimizations(such as -O2/-O3)lead to abnormal stack frame analysis -
objtool cannot comfirm that the stack frames of all branches can be
correctly restored, thus generating false warnings.

Below:
>> sound/core/seq/seq_ump_convert.o: warning: objtool: cc_ev_to_ump_midi2+0x589: return with modified stack frame

So we modify it by uniformly returning at the and of the function.

Signed-off-by: songxiebing <songxiebing@kylinos.cn>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202503200535.J3hAvcjw-lkp@intel.com/
---
v2:
- fix warning: this statement may fall through [-Wimplicit-fallthrough=]
---
 sound/core/seq/seq_ump_convert.c | 35 +++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/sound/core/seq/seq_ump_convert.c b/sound/core/seq/seq_ump_convert.c
index db2f169cae11..ff4ee26adad1 100644
--- a/sound/core/seq/seq_ump_convert.c
+++ b/sound/core/seq/seq_ump_convert.c
@@ -841,7 +841,7 @@ static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
 	unsigned char index = event->data.control.param & 0x7f;
 	unsigned char val = event->data.control.value & 0x7f;
 	struct ump_cvt_to_ump_bank *cc = &dest_port->midi2_bank[channel];
-	int ret;
+	int ret = 0;
 
 	/* process special CC's (bank/rpn/nrpn) */
 	switch (index) {
@@ -851,47 +851,54 @@ static int cc_ev_to_ump_midi2(const struct snd_seq_event *event,
 		cc->cc_rpn_msb = val;
 		if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
 			reset_rpn(cc);
-		return ret;
+		break;
 	case UMP_CC_RPN_LSB:
 		ret = fill_rpn(cc, data, channel, true);
 		cc->rpn_set = 1;
 		cc->cc_rpn_lsb = val;
 		if (cc->cc_rpn_msb == 0x7f && cc->cc_rpn_lsb == 0x7f)
 			reset_rpn(cc);
-		return ret;
+		break;
 	case UMP_CC_NRPN_MSB:
 		ret = fill_rpn(cc, data, channel, true);
 		cc->nrpn_set = 1;
 		cc->cc_nrpn_msb = val;
-		return ret;
+		break;
 	case UMP_CC_NRPN_LSB:
 		ret = fill_rpn(cc, data, channel, true);
 		cc->nrpn_set = 1;
 		cc->cc_nrpn_lsb = val;
-		return ret;
+		break;
 	case UMP_CC_DATA:
 		cc->cc_data_msb_set = 1;
 		cc->cc_data_msb = val;
-		return fill_rpn(cc, data, channel, false);
+		ret = fill_rpn(cc, data, channel, false);
+		break;
 	case UMP_CC_BANK_SELECT:
 		cc->bank_set = 1;
 		cc->cc_bank_msb = val;
-		return 0; // skip
+		ret = 0; // skip
+		break;
 	case UMP_CC_BANK_SELECT_LSB:
 		cc->bank_set = 1;
 		cc->cc_bank_lsb = val;
-		return 0; // skip
+		ret = 0; // skip
+		break;
 	case UMP_CC_DATA_LSB:
 		cc->cc_data_lsb_set = 1;
 		cc->cc_data_lsb = val;
-		return fill_rpn(cc, data, channel, false);
+		ret = fill_rpn(cc, data, channel, false);
+		break;
+	default:
+		data->cc.status = status;
+		data->cc.channel = channel;
+		data->cc.index = index;
+		data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
+		ret = 1;
+		break;
 	}
 
-	data->cc.status = status;
-	data->cc.channel = channel;
-	data->cc.index = index;
-	data->cc.data = upscale_7_to_32bit(event->data.control.value & 0x7f);
-	return 1;
+	return ret;
 }
 
 /* convert one-parameter control event to MIDI 2.0 UMP */
-- 
2.25.1
Re: [PATCH v2] ALSA: core/seq: Optimize the return logic in cc_ev_to_ump_midi2
Posted by Takashi Iwai 1 week ago
On Wed, 25 Mar 2026 02:51:19 +0100,
songxiebing wrote:
> 
> There are multiple early return branches within the func, and compiler
> optimizations(such as -O2/-O3)lead to abnormal stack frame analysis -
> objtool cannot comfirm that the stack frames of all branches can be
> correctly restored, thus generating false warnings.
> 
> Below:
> >> sound/core/seq/seq_ump_convert.o: warning: objtool: cc_ev_to_ump_midi2+0x589: return with modified stack frame
> 
> So we modify it by uniformly returning at the and of the function.
> 
> Signed-off-by: songxiebing <songxiebing@kylinos.cn>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202503200535.J3hAvcjw-lkp@intel.com/
> ---
> v2:
> - fix warning: this statement may fall through [-Wimplicit-fallthrough=]

Basically I don't like to take this kind of change just because a
stupid compiler can't handle it well.  But this particular code change
itself is simple enough, so maybe still worth to take.

Applied to for-next branch now.  Thanks.


Takashi