Skip to content

Commit

Permalink
ALSA: hda - Fix bad dereference of jack object
Browse files Browse the repository at this point in the history
The hda_jack_tbl entries are managed by snd_array for allowing
multiple jacks.  It's good per se, but the problem is that struct
hda_jack_callback keeps the hda_jack_tbl pointer.  Since snd_array
doesn't preserve each pointer at resizing the array, we can't keep the
original pointer but have to deduce the pointer at each time via
snd_array_entry() instead.  Actually, this resulted in the deference
to the wrong pointer on codecs that have many pins such as CS4208.

This patch replaces the pointer to the NID value as the search key.
As an unexpected good side effect, this even simplifies the code, as
only NID is needed in most cases.

Cc: <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Feb 9, 2016
1 parent c44d9b1 commit 2ebab40
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions sound/pci/hda/hda_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4028,9 +4028,9 @@ static void pin_power_callback(struct hda_codec *codec,
struct hda_jack_callback *jack,
bool on)
{
if (jack && jack->tbl->nid)
if (jack && jack->nid)
sync_power_state_change(codec,
set_pin_power_jack(codec, jack->tbl->nid, on));
set_pin_power_jack(codec, jack->nid, on));
}

/* callback only doing power up -- called at first */
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/hda/hda_jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
if (!callback)
return ERR_PTR(-ENOMEM);
callback->func = func;
callback->tbl = jack;
callback->nid = jack->nid;
callback->next = jack->callback;
jack->callback = callback;
}
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/hda/hda_jack.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct hda_jack_callback;
typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);

struct hda_jack_callback {
struct hda_jack_tbl *tbl;
hda_nid_t nid;
hda_jack_callback_fn func;
unsigned int private_data; /* arbitrary data */
struct hda_jack_callback *next;
Expand Down
5 changes: 4 additions & 1 deletion sound/pci/hda/patch_ca0132.c
Original file line number Diff line number Diff line change
Expand Up @@ -4427,13 +4427,16 @@ static void ca0132_process_dsp_response(struct hda_codec *codec,
static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
{
struct ca0132_spec *spec = codec->spec;
struct hda_jack_tbl *tbl;

/* Delay enabling the HP amp, to let the mic-detection
* state machine run.
*/
cancel_delayed_work_sync(&spec->unsol_hp_work);
schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
cb->tbl->block_report = 1;
tbl = snd_hda_jack_tbl_get(codec, cb->nid);
if (tbl)
tbl->block_report = 1;
}

static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/hda/patch_hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
static void jack_callback(struct hda_codec *codec,
struct hda_jack_callback *jack)
{
check_presence_and_report(codec, jack->tbl->nid);
check_presence_and_report(codec, jack->nid);
}

static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/hda/patch_realtek.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void alc_update_knob_master(struct hda_codec *codec,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (!uctl)
return;
val = snd_hda_codec_read(codec, jack->tbl->nid, 0,
val = snd_hda_codec_read(codec, jack->nid, 0,
AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
val &= HDA_AMP_VOLMASK;
uctl->value.integer.value[0] = val;
Expand Down
6 changes: 3 additions & 3 deletions sound/pci/hda/patch_sigmatel.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ static void jack_update_power(struct hda_codec *codec,
if (!spec->num_pwrs)
return;

if (jack && jack->tbl->nid) {
stac_toggle_power_map(codec, jack->tbl->nid,
snd_hda_jack_detect(codec, jack->tbl->nid),
if (jack && jack->nid) {
stac_toggle_power_map(codec, jack->nid,
snd_hda_jack_detect(codec, jack->nid),
true);
return;
}
Expand Down

0 comments on commit 2ebab40

Please sign in to comment.