From patchwork Thu Jun 14 11:22:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhouyang Jia X-Patchwork-Id: 10463983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BCF85603EE for ; Thu, 14 Jun 2018 11:33:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC126289EA for ; Thu, 14 Jun 2018 11:33:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FDAE28A62; Thu, 14 Jun 2018 11:33:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F101F289EA for ; Thu, 14 Jun 2018 11:33:10 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D14882675FA; Thu, 14 Jun 2018 13:22:36 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 304572675FB; Thu, 14 Jun 2018 13:22:34 +0200 (CEST) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by alsa0.perex.cz (Postfix) with ESMTP id 958302675EC for ; Thu, 14 Jun 2018 13:22:31 +0200 (CEST) Received: by mail-pf0-f193.google.com with SMTP id b17-v6so3096964pfi.0 for ; Thu, 14 Jun 2018 04:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WG1ZM92egI9hXvjdDp5M7itqCRH08OMfu4yNNMx5wBI=; b=XC0tfK8aPUPdlH+dL/ffdqjTiKPuqaBuncIcogSjg9hjVUTjSal1EYhFRiku0AaYHL KSCuGEKX2ouLr6bCG+mlxZPCbFuX9Yhc5ygE2PZbvyuan4oqzfO/GyFoabvaaXKLM4+b Bc/MgVUmNDZK9kh0xKntASJuvSlgJF7lvVPKgDBfH+kKNCbyeS9xVMn7Eh7LgyTlyzoq 1+8HM9GgTNS8Ds8zCyu3xRHf41QieVf94bts0hTNmrA7lyCI6CJ3u+bqWazmnwVg2f0G H3DOJ2QeBPd768Kau/GoxIZIifuBi3TfBANfmwbHws7nRHWBY8caH41K4g6S+G645eBN a9Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WG1ZM92egI9hXvjdDp5M7itqCRH08OMfu4yNNMx5wBI=; b=TgrH7ZbIrVC596ZuGax5nUafZdwAmb5X69QPy59U13kf0/07P2O3FWt55wuGeS8Sap QJVOUU2EMPGi2n9LfwRaEeiyzTnxBeD1p0n9cCUkaRzsJw+iVje2dJ/S9Iw5qOK810Z+ NU6N7omn25lph8ZnIJyXnBnDdsaTuKvdStG3E5G1tY4PPDilgnUZ6xgMm9gk0cL1hPD2 B10SZnqDqJopG1cfPJwuWJTu2pK172ZNyFZXYG9UqnwfuEjNZ/1E834jlVeMC1xzngU9 aOX5td3fnHH9yWcUeKYt8iOy7pFp1/2GrOaymlPaOUoL72KkNS8zuDMHNkWTlZI93rZD Lu3A== X-Gm-Message-State: APt69E0R+PxbgboGD/UKTO8Mo473wI2F6MHeaRHKcX1UuEtOScGMu4FU Vw+XcvQLGAAuJrn1JzpGF1s= X-Google-Smtp-Source: ADUXVKJXRCw1wBhBMNsYtNnWHGgCc5SeOlvT0jpP9m0k3T5LG6PvUpE1T97fFzcwObttHLp99E3JPw== X-Received: by 2002:a65:4a92:: with SMTP id b18-v6mr1913957pgu.107.1528975349943; Thu, 14 Jun 2018 04:22:29 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id c4-v6sm10784525pfe.53.2018.06.14.04.22.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 04:22:29 -0700 (PDT) From: Zhouyang Jia To: Date: Thu, 14 Jun 2018 19:22:18 +0800 Message-Id: <1528975341-51696-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528704521-34060-1-git-send-email-jiazhouyang09@gmail.com> References: <1528704521-34060-1-git-send-email-jiazhouyang09@gmail.com> Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Takashi Iwai , Zhouyang Jia , Bhumika Goyal Subject: [alsa-devel] [PATCH v2] ALSA: sonicvibes: add error handling for snd_ctl_add X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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; + } if ((err = snd_card_register(card)) < 0) { snd_card_free(card);