From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by aws-us-west-2-korg-lkml-1.web.codeaurora.org (Postfix) with ESMTP id 96251C07D5C for ; Thu, 14 Jun 2018 11:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C466208CB for ; Thu, 14 Jun 2018 11:30:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C466208CB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755080AbeFNLaY (ORCPT ); Thu, 14 Jun 2018 07:30:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:37257 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754957AbeFNLaX (ORCPT ); Thu, 14 Jun 2018 07:30:23 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E13B5ACF6; Thu, 14 Jun 2018 11:30:21 +0000 (UTC) Date: Thu, 14 Jun 2018 13:30:21 +0200 Message-ID: From: Takashi Iwai To: "Zhouyang Jia" Cc: , "Bhumika Goyal" , "Jaroslav Kysela" , Subject: Re: [PATCH v2] ALSA: sonicvibes: add error handling for snd_ctl_add In-Reply-To: <1528975341-51696-1-git-send-email-jiazhouyang09@gmail.com> References: <1528704521-34060-1-git-send-email-jiazhouyang09@gmail.com> <1528975341-51696-1-git-send-email-jiazhouyang09@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 Jun 2018 13:22:18 +0200, Zhouyang Jia wrote: > > When snd_ctl_add fails, the lack of error-handling code may > cause unexpected results. > > This patch adds error-handling code after calling snd_ctl_add. > > Signed-off-by: Zhouyang Jia > --- > v1->v2: > - Check the return value of snd_sonicvibes_create_gameport. > --- > sound/pci/sonicvibes.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c > index a8abb15..75225b04 100644 > --- a/sound/pci/sonicvibes.c > +++ b/sound/pci/sonicvibes.c > @@ -1188,6 +1188,7 @@ SONICVIBES_SINGLE("Joystick Speed", 0, SV_IREG_GAME_PORT, 1, 15, 0); > static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic) > { > struct gameport *gp; > + int err; > > sonic->gameport = gp = gameport_allocate_port(); > if (!gp) { > @@ -1203,7 +1204,10 @@ static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic) > > gameport_register_port(gp); > > - snd_ctl_add(sonic->card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic)); > + err = snd_ctl_add(sonic->card, > + snd_ctl_new1(&snd_sonicvibes_game_control, sonic)); > + if (err < 0) > + return err; > > return 0; > } > @@ -1515,7 +1519,10 @@ static int snd_sonic_probe(struct pci_dev *pci, > return err; > } > > - snd_sonicvibes_create_gameport(sonic); > + if ((err = snd_sonicvibes_create_gameport(sonic)) < 0) { > + snd_card_free(card); > + return err; > + } You don't need to inherit the old-fashioned style "if ((err = xxx)" in a new code. Check what checkpatch.pl complains. thanks, Takashi