Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp966422ybt; Fri, 10 Jul 2020 17:55:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrKbV7AM+x6I77SM3hCLCs9WUuraoEIrgmH9ojni03jVNRN3o0EASbB07bVRY96FH90X9B X-Received: by 2002:aa7:c3d8:: with SMTP id l24mr71478831edr.97.1594428954293; Fri, 10 Jul 2020 17:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594428954; cv=none; d=google.com; s=arc-20160816; b=Bi56HZBrdQchb2vVMmUxIEXh44FktHlsWa7TjamvMUOAASf/S+r1iCd5X8u+IJzwRt w81YOwKlOpRmX4vlqRLWn8T07WoeSPKY/vEdd8vgxSdtYXEQ8qRK76ZuEA3ZRnuocWxy 2bYSRjQLzgPFZUoxq7b5ucV/YKZVBihhP8UefJQwPgAhXFDsjg4XDG0+i89Br/T7NZtk m/Wyq+XyCH84uVOzEdutb02BqkdfqU20Kk+8CUG6TRWWwUIUVMn/sznctaMoJrto3EGb 24sx6m49Zghhr8ClSUPGR55QCr/G1vuTypPtKwFc82jYWxiezTiUQswQKaLTBrACExrj 2KXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1Rls/U/lDsLfT4D3DE5n9+9Nu0A90fUMZ5H2LpZadpY=; b=dqle8EHoiRfD678K3H1oGYWkQjV3PrNNz7tB+utIWURqfvJHQdIHFcFV9uiAA9lBGu 0u+BS6zz/m3zguesy2a5tYqEYn5dpfJdX4P+ou59J+T0OX08e2p/5DPw3feW6/TigLgR xlBaKLMDd51LwEBx/Jj2nPiilUS0dwCLDE5olbOTZvnQbHsvGzXPI7ees2tte63yTYoB CdLWlvaIduMmqvAJpzV3lN53uwZDnsxlj3MW25ouNzYStCd6UAzUFsjLQwZllh3Xm4Sk oa+ov2hy1kRbvEhJnOdVSBirghod2HtDm7Z/oPx6YVJqVElguzHTwwdPbyw1bg/wXpIO g7yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=iPPbSg9Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm7si5084806edb.43.2020.07.10.17.55.31; Fri, 10 Jul 2020 17:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=iPPbSg9Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbgGKAxD (ORCPT + 99 others); Fri, 10 Jul 2020 20:53:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbgGKAxD (ORCPT ); Fri, 10 Jul 2020 20:53:03 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E59A1C08C5DC for ; Fri, 10 Jul 2020 17:53:02 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id z17so5937663edr.9 for ; Fri, 10 Jul 2020 17:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1Rls/U/lDsLfT4D3DE5n9+9Nu0A90fUMZ5H2LpZadpY=; b=iPPbSg9QOhO1/J2AGGABUiWYW1G+aZBlYGBwtZRUeuvTEkRismRqyyYYb/b5HtXFzD eT6GM4fHT57mSqaeCJSPWS/lhpqKIIW/IEcSX0sOK4gzky06Dhnp/Ip1OIIpfdUL4I9D zaf7XYwr0+dyWUSgZz/fIP6VpjQimltNJozru9KMByXvX/GmYaTxeawAnzBI049LwHqK QyTtiHGsXlvVd8xwGIQmR9G52VI1TJAAt9K92hcxV/pbQ4SMotmatFqvGtbVlMbDTsbL X0IogtzxzfRftbdheB9eRV8vW+J7XAIlFm6MBfLuy3kRg+Ca6FB45eVJjJ060lXd8Yag +wpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1Rls/U/lDsLfT4D3DE5n9+9Nu0A90fUMZ5H2LpZadpY=; b=kgcQjewRc1/IMvMf8HTtlBN262Fxrw3q7k4X8Bnx6qdybvyf8jZc7l+H2kOrWO50Xc 4UqXVabdmd7N+6JqZhq+UCAbVplCmsdCTNliXMiCfjt/We0kCjlUxcth5Qqu6MlGi3s9 UEM4+cCaUHhRQAm4D2GFOcTrFpvccPTcNzbHD9Sv8jRsCLZyjKy7FLM7K1MwhgFWuMZk gHbKAXPztmJJdkri6ktnc6mD99pKxzHE74/qfBxQAckuMWaOfKHb+Mdk2NBdx98ZME2T pP/91MmW8MS/NNPbKW5l5IW5y9SEulj3KX9/hgJfAD0x5sTsjocl/GDIQGn3RFkg4pbY 9X8Q== X-Gm-Message-State: AOAM533lNKSHP8Y4rNPQG8of9CqCwWUoXZ+as8XTEu+Upz3H2zpAFzTN +IvF6Y3jEJmZBqZVKpbrwaoXQGGsMuee4e3ZnsxMDQ== X-Received: by 2002:a50:a1e7:: with SMTP id 94mr77926426edk.165.1594428781622; Fri, 10 Jul 2020 17:53:01 -0700 (PDT) MIME-Version: 1.0 References: <158500767138.2088294.17131646259803932461.stgit@dwillia2-desk3.amr.corp.intel.com> <158500773552.2088294.8756587190550753100.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: From: Dan Williams Date: Fri, 10 Jul 2020 17:52:50 -0700 Message-ID: Subject: Re: [PATCH 11/12] device-dax: Add dis-contiguous resource support To: Joao Martins Cc: Linux MM , Vishal L Verma , Dave Hansen , Christoph Hellwig , linux-nvdimm , Linux Kernel Mailing List , jmoyer Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 12, 2020 at 7:37 AM Joao Martins wrote: > > On 3/23/20 11:55 PM, Dan Williams wrote: > > @@ -561,13 +580,26 @@ static int __alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > > if (start == U64_MAX) > > return -EINVAL; > > > > + ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > > + * (dev_dax->nr_range + 1), GFP_KERNEL); > > + if (!ranges) > > + return -ENOMEM; > > + > > alloc = __request_region(res, start, size, dev_name(dev), 0); > > - if (!alloc) > > + if (!alloc) { > > + kfree(ranges); > > return -ENOMEM; > > + } > > Noticed this yesterday while looking at alloc_dev_dax_range(). > > Is it correct to free @ranges here on __request_region failure? > > IIUC krealloc() would free dev_dax->ranges if it succeeds, leaving us without > any valid ranges if __request_region failure case indeed frees @ranges. These > @ranges are being used afterwards when we delete the interface and free the > assigned regions. Perhaps we should remove the kfree() above and set > dev_dax->ranges instead before __request_region; or alternatively change the > call order between krealloc and __request_region? FWIW, krealloc checks if the > object being reallocated already meets the requested size, so perhaps there's no > harm with going with the former. Yeah, the kfree is bogus. It can just wait until the device is destroyed to be freed, but only if there is an existing allocation. If this is a new allocation then nothing else will do the kfree.