From patchwork Fri Jul 6 17:21:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10512205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 90EA7603D7 for ; Fri, 6 Jul 2018 17:23:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 745F82874F for ; Fri, 6 Jul 2018 17:23:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6859D2876C; Fri, 6 Jul 2018 17:23:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08EF92873B for ; Fri, 6 Jul 2018 17:23:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933748AbeGFRXM (ORCPT ); Fri, 6 Jul 2018 13:23:12 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:40590 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932895AbeGFRXL (ORCPT ); Fri, 6 Jul 2018 13:23:11 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w66HIx6Z165011; Fri, 6 Jul 2018 17:22:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=7mIZxAbAGfh3KUXuGxCaXy98mD/gDQkrQHsAirC0ohI=; b=V/SVHhKsBwwaryt+aCOfNA1z4HB9BVwgT7pagx4PO2H1jhrEXBODpxs7gjRR0NC9q3IC HylMi7FElw/hGwO5cfd2WwevMb8halAmGHjW+vPHMzSXLtOcB9PfA2A1Q2cmhuxrc2k8 /VlD3G7wVfarUKKVJbLAds6MQV0wL/LdDPh7BAAcUNk8h4kpkTGnb5DYFbjxKTcPU6EH bfN1W6HQjFQms9293uI20a6AwbPRT8/nA2PY3QKRl2SVAMlofCDhz1e5MIb2h5rXsvkT QxnoUmKNN/464M8eQXxec4aVyfpO0Sv67bx+8eVUHZYrdo+58XeyG1lXoMbezVtpFvFK hw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2k0dnjtg3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jul 2018 17:22:51 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w66HMoJW008242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Jul 2018 17:22:51 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w66HMoYS011251; Fri, 6 Jul 2018 17:22:50 GMT Received: from kili.mountain (/197.157.34.168) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 06 Jul 2018 10:22:50 -0700 Date: Fri, 6 Jul 2018 20:21:01 +0300 From: Dan Carpenter To: Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] xarray: unlock on error in xa_alloc() Message-ID: <20180706172101.vvp3fv3l244y2p7w@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8945 signatures=668704 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807060192 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need to unlock on this error path. Fixes: 29a6bfc32eb2 ("xarray: Track free entries in an XArray") Signed-off-by: Dan Carpenter --- There "UINT_MAX + 1" is an integer overflow and is equal to zero but I don't know what was intended there. diff --git a/lib/xarray.c b/lib/xarray.c index be10039caaed..a27fdb381f64 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1474,8 +1474,10 @@ int xa_alloc(struct xarray *xa, u32 *id, void *entry, gfp_t gfp) xas.xa_index = 0; xas_lock(&xas); xas_find_tagged(&xas, UINT_MAX, XA_FREE_TAG); - if (xas.xa_node == XAS_BOUNDS && xas.xa_index == UINT_MAX + 1) + if (xas.xa_node == XAS_BOUNDS && xas.xa_index == UINT_MAX + 1) { + xas_unlock(&xas); return -ENOSPC; + } *id = xas.xa_index; xas_store(&xas, entry); xas_clear_tag(&xas, XA_FREE_TAG);