Skip to content

Commit 5265db2

Browse files
PhilPottergregkh
authored andcommitted
isdn: mISDN: correctly handle ph_info allocation failure in hfcsusb_ph_info
Modify return type of hfcusb_ph_info to int, so that we can pass error value up the call stack when allocation of ph_info fails. Also change three of four call sites to actually account for the memory failure. The fourth, in ph_state_nt, is infeasible to change as it is in turn called by ph_state which is used as a function pointer argument to mISDN_initdchannel, which would necessitate changing its signature and updating all the places where it is used (too many). Fixes original flawed commit (38d2265) from the University of Minnesota. Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Phillip Potter <phil@philpotter.co.uk> Link: https://lore.kernel.org/r/20210503115736.2104747-48-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 36a2c87 commit 5265db2

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎drivers/isdn/hardware/mISDN/hfcsusb.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void hfcsusb_start_endpoint(struct hfcsusb *hw, int channel);
4646
static void hfcsusb_stop_endpoint(struct hfcsusb *hw, int channel);
4747
static int hfcsusb_setup_bch(struct bchannel *bch, int protocol);
4848
static void deactivate_bchannel(struct bchannel *bch);
49-
static void hfcsusb_ph_info(struct hfcsusb *hw);
49+
static int hfcsusb_ph_info(struct hfcsusb *hw);
5050

5151
/* start next background transfer for control channel */
5252
static void
@@ -241,14 +241,17 @@ hfcusb_l2l1B(struct mISDNchannel *ch, struct sk_buff *skb)
241241
* send full D/B channel status information
242242
* as MPH_INFORMATION_IND
243243
*/
244-
static void
244+
static int
245245
hfcsusb_ph_info(struct hfcsusb *hw)
246246
{
247247
struct ph_info *phi;
248248
struct dchannel *dch = &hw->dch;
249249
int i;
250250

251251
phi = kzalloc(struct_size(phi, bch, dch->dev.nrbchan), GFP_ATOMIC);
252+
if (!phi)
253+
return -ENOMEM;
254+
252255
phi->dch.ch.protocol = hw->protocol;
253256
phi->dch.ch.Flags = dch->Flags;
254257
phi->dch.state = dch->state;
@@ -260,6 +263,8 @@ hfcsusb_ph_info(struct hfcsusb *hw)
260263
_queue_data(&dch->dev.D, MPH_INFORMATION_IND, MISDN_ID_ANY,
261264
struct_size(phi, bch, dch->dev.nrbchan), phi, GFP_ATOMIC);
262265
kfree(phi);
266+
267+
return 0;
263268
}
264269

265270
/*
@@ -344,8 +349,7 @@ hfcusb_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)
344349
ret = l1_event(dch->l1, hh->prim);
345350
break;
346351
case MPH_INFORMATION_REQ:
347-
hfcsusb_ph_info(hw);
348-
ret = 0;
352+
ret = hfcsusb_ph_info(hw);
349353
break;
350354
}
351355

@@ -400,8 +404,7 @@ hfc_l1callback(struct dchannel *dch, u_int cmd)
400404
hw->name, __func__, cmd);
401405
return -1;
402406
}
403-
hfcsusb_ph_info(hw);
404-
return 0;
407+
return hfcsusb_ph_info(hw);
405408
}
406409

407410
static int
@@ -743,8 +746,7 @@ hfcsusb_setup_bch(struct bchannel *bch, int protocol)
743746
handle_led(hw, (bch->nr == 1) ? LED_B1_OFF :
744747
LED_B2_OFF);
745748
}
746-
hfcsusb_ph_info(hw);
747-
return 0;
749+
return hfcsusb_ph_info(hw);
748750
}
749751

750752
static void

0 commit comments

Comments
 (0)