Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4612090imm; Wed, 30 May 2018 08:42:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLD1TUO0oSxiAFwxx9worOeq9g62Wl++xfTiQvKOH3yG0Ds26EldMu2k9Houh9V8fCLyUhQ X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr3392480plb.26.1527694934922; Wed, 30 May 2018 08:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527694934; cv=none; d=google.com; s=arc-20160816; b=iMgZdjWMC9A03ZbvtNiekYTGD2zDY1EhYZkcoin39wsSLWsRNneh6OdcrFLY8HtQ6Y JR8Z/Hm1lzltA6tLpQSMj5jAnack4rhxxPD7/JM1naNnzR61dzCEgFtQNBrQD2KepVdW fRGt3n/kjhbv7cEKjUvJQY3OA6g7E/BKiVQhU6ChH8PJV//nQB4ZJu5MP05saxtX/9qD xNUfnK9TN9EhNhdYaN76XLY/ciBPGl/6jG01D49XrDxMFS1oyrLXRKenn3UFRS/UVOO+ L/Qz3zen/sZlGBw4/UsnU4J9qXvDF+IkIgSbF7o7Cc0bFaoUkWO+cfF8adMPAQxmGbuM m1kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=YD2rVRuuCjX7MIZPfthNOPVBLevfudvNkxZ9Hk7rVfg=; b=zlUpa8U4DIfWue5IPan7Z2L5CyD08zxrlG3Lb1YrnagEX5oE7c8YgNBw1syG4pEdkv ZoLTuLuFmle3Uj1peDsleslrdpTSxW6TTGgYzy/tYrOa04Ep1AfykFmnp8alYS+2DhCV v1NQfnZ3XgNQC1WoR/QaovO67skul1kCZQK6D9nIZ51PLwBnKeMkj48CHqa43DGIDYPx BMJl/lGK1dyixAvfTxMuIyP9vYkb9l9W0Lfi3CoegT2nVN6U0phyY3G0q/GU6ky5R/5A 0abKqG6GVG61VeBWkDlLn3hpCTc5jBeOwCQzxcK2apVPVAfiK1ATLMeisxQKRQ97V8un jRCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eW7SFrRb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11-v6si22624670pgt.356.2018.05.30.08.42.00; Wed, 30 May 2018 08:42:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eW7SFrRb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753605AbeE3PlN (ORCPT + 99 others); Wed, 30 May 2018 11:41:13 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55462 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751605AbeE3PlL (ORCPT ); Wed, 30 May 2018 11:41:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=YD2rVRuuCjX7MIZPfthNOPVBLevfudvNkxZ9Hk7rVfg=; b=eW7SFrRbk0jaCKoSb6Iu09Tz9 oJDndnuG0+YZ+/qyS/Af06lHA5R0MBCLme0YKrNcJ3i/xrqDhDek29v78pPiyeBUl0VTByNE+0dua yUnygRRzkPGQTOAqzEKXioufN3Bu24WKWMucLREeNdmrRbQDplNXbFaaT+nI4tMTSRNmyVW3pBJPo yNKu5wLYYCGzSKjKeeU6eGIhGcVu9plWzF6jVngprT9GXHhL15Fc9mb5qU1MyXge5FKf4r/zCVt+C TkWXjnCl3zd69GgETA+jfMNbsRJ71R7oYFqKHwlma7CxfaJmKRyCqGkgZzmqosPUk+WLkCYPAuCwg noVn2dgkg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fO3Dq-0000Wo-BL; Wed, 30 May 2018 15:41:10 +0000 Date: Wed, 30 May 2018 08:41:10 -0700 From: Matthew Wilcox To: Baolin Wang Cc: linux-mm@kvack.org, LKML , Arnd Bergmann , Mark Brown Subject: Re: [PATCH] mm: dmapool: Check the dma pool name Message-ID: <20180530154110.GA22184@bombadil.infradead.org> References: <59623b15001e5a20ac32b1a393db88722be2e718.1527679621.git.baolin.wang@linaro.org> <20180530120133.GC17450@bombadil.infradead.org> <20180530151327.GA13951@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180530151327.GA13951@bombadil.infradead.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 30, 2018 at 08:13:27AM -0700, Matthew Wilcox wrote: > On Wed, May 30, 2018 at 08:14:09PM +0800, Baolin Wang wrote: > > On 30 May 2018 at 20:01, Matthew Wilcox wrote: > > > On Wed, May 30, 2018 at 07:28:43PM +0800, Baolin Wang wrote: > > >> It will be crash if we pass one NULL name when creating one dma pool, > > >> so we should check the passing name when copy it to dma pool. > > > > > > NAK. Crashing is the appropriate thing to do. Fix the caller to not > > > pass NULL. > > > > > > If you permit NULL to be passed then you're inviting crashes or just > > > bad reporting later when pool->name is printed. > > > > I think it just prints one NULL pool name. Sometimes the device > > doesn't care the dma pool names, so I think we can make code more > > solid to valid the passing parameters like other code does. > > Or can we add check to return NULL when the passing name is NULL > > instead of crashing the kernel? Thanks. > > No. Fix your driver. Let me elaborate on this. Kernel code is supposed to be "reasonable". That means we don't check every argument to every function for sanity, unless it's going to cause trouble later. Crashing immediately with a bogus argument is fine; you can see the problem and fix it immediately. Returning NULL with a bad argument is actually worse; you won't know why the function returned NULL (maybe we're out of memory?) and you'll have a more complex debugging experience. Sometimes it makes sense to accept a NULL pointer and do something reasonable, like kfree(). In this case, we can eliminate checks in all the callers. But we don't, in general, put sanity checks on arguments without a good reason. Your reasons aren't good. "The driver doesn't care" -- well, just pass the driver's name, then.