Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15c726ea authored by Vaibhav Agarwal's avatar Vaibhav Agarwal Committed by Greg Kroah-Hartman
Browse files

greybus: audio: Add check for invalid index while mapping control



While mapping control id to define DAPM routes, invalid control index
may cause kernel oops. Add extra check to validate index while mapping
names to control_id.

Signed-off-by: default avatarVaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: default avatarMark Greer <mgreer@animalcreek.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 0900845a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ struct gbaudio_control {
	char *name;
	char *wname;
	const char * const *texts;
	int items;
	struct list_head list;
};

+6 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ static const char *gbaudio_map_controlid(struct gbaudio_module_info *module,
		if (control->id == control_id) {
			if (index == GBAUDIO_INVALID_ID)
				return control->name;
			if (index >= control->items)
				return NULL;
			return control->texts[index];
		}
	}
@@ -71,6 +73,8 @@ static const char *gbaudio_map_controlid(struct gbaudio_module_info *module,
		if (control->id == control_id) {
			if (index == GBAUDIO_INVALID_ID)
				return control->name;
			if (index >= control->items)
				return NULL;
			return control->texts[index];
		}
	}
@@ -1038,6 +1042,7 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
			csize += gbenum->names_length;
			control->texts = (const char * const *)
				gb_generate_enum_strings(module, gbenum);
			control->items = gbenum->items;
		} else
			csize = sizeof(struct gb_audio_control);
		*w_size += csize;
@@ -1184,6 +1189,7 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module,
			csize += gbenum->names_length;
			control->texts = (const char * const *)
				gb_generate_enum_strings(module, gbenum);
			control->items = gbenum->items;
		} else
			csize = sizeof(struct gb_audio_control);