From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933108AbcBIV4n (ORCPT ); Tue, 9 Feb 2016 16:56:43 -0500 Received: from mx2.suse.de ([195.135.220.15]:56137 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932936AbcBIV4m (ORCPT ); Tue, 9 Feb 2016 16:56:42 -0500 Date: Tue, 09 Feb 2016 22:56:39 +0100 Message-ID: From: Takashi Iwai To: "Jerome Marchand" Cc: "Jaroslav Kysela" , , Subject: Re: Should snd_card_free() check for null pointer? In-Reply-To: <56B9F7F8.1000605@redhat.com> References: <56B9F7F8.1000605@redhat.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/24.5 (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, 09 Feb 2016 15:30:16 +0100, Jerome Marchand wrote: > > Hi, > > Before commit f24640648186b (ALSA: Use standard device refcount for card > accounting), snd_card_free() would return -EINVAL on a null pointer. Now > it ends up in a null pointer dereference. There is at least one driver > that can call snd_card_free() with null argument: saa7134_alsa. It can > easily be triggered by just inserting and removing the module (no need > to have the hardware). > I don't think that is a rule, but it seems that the standard behavior of > *_free() functions is to check for null pointer. What do you think? Well, I have a mixed feeling about this. Allowing NULL sometimes makes the code easier. OTOH, caling snd_card_free() with NULL is really an unexpected situation, and if a driver does it, most likely it does something weird. So, at this moment, I would fix the caller side. But, it's not a final call, just my gut feeling. thanks, Takashi