From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: Re: [PATCH v2 2/9] dmapool: cleanup error messages Date: Fri, 3 Aug 2018 14:07:45 -0700 Message-ID: <20180803210745.GB9329@bombadil.infradead.org> References: <7a943124-c65e-f0ed-cc5c-20b23f021505@cybernetics.com> <20180803162212.GA4718@bombadil.infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Tony Battersby Cc: linux-scsi , Chaitra P B , Suganath Prabu Subramani , Sathya Prakash , iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-mm , Andy Shevchenko , MPT-FusionLinux.pdl-dY08KVG/lbpWk0Htik3J/w@public.gmane.org, Christoph Hellwig List-Id: linux-scsi@vger.kernel.org On Fri, Aug 03, 2018 at 02:43:07PM -0400, Tony Battersby wrote: > Out of curiosity, I just tried to create a dmapool with a NULL dev and > it crashed on this: > > static inline int dev_to_node(struct device *dev) > { > return dev->numa_node; > } > > struct dma_pool *dma_pool_create(const char *name, struct device *dev, > size_t size, size_t align, size_t boundary) > { > ... > retval = kmalloc_node(sizeof(*retval), GFP_KERNEL, dev_to_node(dev)); > ... > } > > So either it needs more special cases for supporting a NULL dev, or the > special cases can be removed since no one does that anyway. Actually, it's worse. dev_to_node() works with a NULL dev ... unless CONFIG_NUMA is set. So we're leaving a timebomb by pretending to allow it. Let's just 'if (!dev) return NULL;' early in create. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 581406B0005 for ; Fri, 3 Aug 2018 17:07:51 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id m4-v6so3094661pgq.19 for ; Fri, 03 Aug 2018 14:07:51 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 1-v6si5610577pgj.128.2018.08.03.14.07.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Aug 2018 14:07:50 -0700 (PDT) Date: Fri, 3 Aug 2018 14:07:45 -0700 From: Matthew Wilcox Subject: Re: [PATCH v2 2/9] dmapool: cleanup error messages Message-ID: <20180803210745.GB9329@bombadil.infradead.org> References: <7a943124-c65e-f0ed-cc5c-20b23f021505@cybernetics.com> <20180803162212.GA4718@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: owner-linux-mm@kvack.org List-ID: To: Tony Battersby Cc: Andy Shevchenko , Christoph Hellwig , Marek Szyprowski , Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , iommu@lists.linux-foundation.org, linux-mm , linux-scsi , MPT-FusionLinux.pdl@broadcom.com On Fri, Aug 03, 2018 at 02:43:07PM -0400, Tony Battersby wrote: > Out of curiosity, I just tried to create a dmapool with a NULL dev and > it crashed on this: > > static inline int dev_to_node(struct device *dev) > { > return dev->numa_node; > } > > struct dma_pool *dma_pool_create(const char *name, struct device *dev, > size_t size, size_t align, size_t boundary) > { > ... > retval = kmalloc_node(sizeof(*retval), GFP_KERNEL, dev_to_node(dev)); > ... > } > > So either it needs more special cases for supporting a NULL dev, or the > special cases can be removed since no one does that anyway. Actually, it's worse. dev_to_node() works with a NULL dev ... unless CONFIG_NUMA is set. So we're leaving a timebomb by pretending to allow it. Let's just 'if (!dev) return NULL;' early in create.