Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Simplify major/minor non-dynamic logic

changeset 6bbf7a855d20 ("media: dvbdev: convert DVB device types into an enum")
added a new warning on gcc 6:

>> drivers/media/dvb-core/dvbdev.c:86:1: warning: control reaches end of non-void function [-Wreturn-type]

That's because gcc is not smart enough to see that all types are
present at the switch. Also, the current code is not too optimized.

So, replace it to a more optimized one, based on a static table.

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Fixes: 6bbf7a855d20 ("media: dvbdev: convert DVB device types into an enum")
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

+13 -15
+13 -15
drivers/media/dvb-core/dvbdev.c
··· 68 68 #else 69 69 #define DVB_MAX_IDS 4 70 70 71 - static int nums2minor(int num, enum dvb_device_type type, int id) 72 - { 73 - int n = (num << 6) | (id << 4); 71 + static const u8 minor_type[] = { 72 + [DVB_DEVICE_VIDEO] = 0, 73 + [DVB_DEVICE_AUDIO] = 1, 74 + [DVB_DEVICE_SEC] = 2, 75 + [DVB_DEVICE_FRONTEND] = 3, 76 + [DVB_DEVICE_DEMUX] = 4, 77 + [DVB_DEVICE_DVR] = 5, 78 + [DVB_DEVICE_CA] = 6, 79 + [DVB_DEVICE_NET] = 7, 80 + [DVB_DEVICE_OSD] = 8, 81 + }; 74 82 75 - switch (type) { 76 - case DVB_DEVICE_VIDEO: return n; 77 - case DVB_DEVICE_AUDIO: return n | 1; 78 - case DVB_DEVICE_SEC: return n | 2; 79 - case DVB_DEVICE_FRONTEND: return n | 3; 80 - case DVB_DEVICE_DEMUX: return n | 4; 81 - case DVB_DEVICE_DVR: return n | 5; 82 - case DVB_DEVICE_CA: return n | 6; 83 - case DVB_DEVICE_NET: return n | 7; 84 - case DVB_DEVICE_OSD: return n | 8; 85 - } 86 - } 83 + #define nums2minor(num, type, id) \ 84 + (((num) << 6) | ((id) << 4) | minor_type[type]) 87 85 88 86 #define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64) 89 87 #endif