From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752530AbdAYVbV (ORCPT ); Wed, 25 Jan 2017 16:31:21 -0500 Received: from mx2.suse.de ([195.135.220.15]:32924 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752142AbdAYVbT (ORCPT ); Wed, 25 Jan 2017 16:31:19 -0500 Date: Wed, 25 Jan 2017 22:31:07 +0100 Message-ID: From: Takashi Iwai To: "Arvind Yadav" Cc: , , Subject: Re: [PATCH v3] ALSA: ymfpci: Handle return NULL error from ioremap_nocache In-Reply-To: <1485235886-30813-1-git-send-email-arvind.yadav.cs@gmail.com> References: <1485235886-30813-1-git-send-email-arvind.yadav.cs@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.1 (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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 24 Jan 2017 06:31:26 +0100, Arvind Yadav wrote: > > Here, If ioremap_nocache will fail. It will return NULL. > Kernel can run into a NULL-pointer dereference. > This error check will avoid NULL pointer dereference. > > Signed-off-by: Arvind Yadav > --- > sound/pci/ymfpci/ymfpci_main.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c > index ffee284..8be1f07 100644 > --- a/sound/pci/ymfpci/ymfpci_main.c > +++ b/sound/pci/ymfpci/ymfpci_main.c > @@ -2392,6 +2392,10 @@ int snd_ymfpci_create(struct snd_card *card, > chip->rev = pci->revision; > chip->reg_area_phys = pci_resource_start(pci, 0); > chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000); > + if (!chip->reg_area_virt) { > + snd_ymfpci_free(chip); The function calls iounmap() unconditionally, so it's not appropriate to call as is. You need to fix snd_ymfpci_free() as well to check NULL before iounmap(). Or, call here kfree() and pci_disable_device() explicitly instead of a full destructor. thanks, Takashi