Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3467634rdh; Thu, 28 Sep 2023 12:31:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrYaza6PWhOoaqu2AaNPkluBBGbJtSWk3WDHWtNeSoO9KeYWxiR3N7V6/ZYJOT7x+Ra+jr X-Received: by 2002:a05:6870:9581:b0:1bb:c0ee:5536 with SMTP id k1-20020a056870958100b001bbc0ee5536mr2103351oao.47.1695929488409; Thu, 28 Sep 2023 12:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695929488; cv=none; d=google.com; s=arc-20160816; b=SipnSOWJ17ABFMszEXC/buhX+XgVKq0o2Rzd61opdoZ8kBqEt1fgBmL6vwEMgWbgy6 BZX01u2gBxVlqmH/wF/HS9KJw3Yg/GSfhSAsybSSnxjqW8JzuflWQEQjI3w0zL8dg4mj cCPZduLsh+ofO0/AhhSz39/uWxpjRDOO65x6iqTLcz5dDZyTechJzGJhu+zEElSNfSzj WCWaBsINTbY0vaHLT7Urd5JoZrbusL6CMRN3WgLxdsvkD+Rbi79ECaG6RjxMkbaFpIbZ ttpnQtXRj76yUAoNu2AaTH5I8Pwm1T6oroGY2ThwGe2b7UpVRMcMPArW8d1s0xEMiy4c Hslw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6lUaiAsD9uV0//FhVSk6Od3pR7CJd+sOtqQwhqcrEfk=; fh=RJtDtIzp+XKCLECA+ZVLgVMDnVWdWSuhpGBLsrEIs60=; b=NsZ7H5R6Llu0ILc7yBlVpogY5Y0yg4vN0CP+ct3do3VcaFfJ8VHb1db05DajzrhbfH kA1pnLZ8lz3p8+FmP9rlgFgycTAuIzKCxp+eFemF2bI9JRvLFTxN1m20wpuWHfVqv20f x8c0vnF5u5qwxQl9MvIWxgzmGf06d3LQDB6KZaZov+N0xPlqr9B2o1jTqDVhI70ireww NpHgRTIyvF06NmQpwyykpK3s0T4SNJHNEC7s0FN472m80QkcACz8xDOeuOfacho7xG1K FWen0fe87B1j3LshOv1fvbAW7Nh/yLJvZqqleOpkwGo/7pW1RyYlj0GbGHYj22c78nJM V1lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=xPCPSdZo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z11-20020a6552cb000000b005824bad8f85si4238440pgp.854.2023.09.28.12.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 12:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=xPCPSdZo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9CF1482B2057; Thu, 28 Sep 2023 11:24:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231451AbjI1SXw (ORCPT + 99 others); Thu, 28 Sep 2023 14:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjI1SXu (ORCPT ); Thu, 28 Sep 2023 14:23:50 -0400 Received: from mail-vs1-xe34.google.com (mail-vs1-xe34.google.com [IPv6:2607:f8b0:4864:20::e34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3636AC for ; Thu, 28 Sep 2023 11:23:48 -0700 (PDT) Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-4527d436ddfso6307075137.1 for ; Thu, 28 Sep 2023 11:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695925428; x=1696530228; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6lUaiAsD9uV0//FhVSk6Od3pR7CJd+sOtqQwhqcrEfk=; b=xPCPSdZov6JOwl5X9QWXEoqop+2np/fyd6BkgmT+MIEYV8h5RElQ8q8crc8KQC5vr6 bC3Rbt1+11NIzI7QzTmG5skbCttfSHlrcnwTmTmWNWwDXnEiOiZ0EWwAwocs//OnkfR1 OQxdRZ4NfLGrHad0WUTNcok2txcRONeUSkxUfoJynysh2TUkIJJjM45+wEOSkplSkeIF wRKIkHqT+nCyUXN6+gD5u2SkbiKACi+IE+elN3OQZ3FEvcryQyfAHfuHJK95DQ2xqVNy HlMRmTdHctv5QsRvlPlYtzFNkm9FJEcGOpYnmHDVPTb6+NDCd6OHCOz1HIDtd93/RvfU svJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695925428; x=1696530228; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6lUaiAsD9uV0//FhVSk6Od3pR7CJd+sOtqQwhqcrEfk=; b=ANAtv58fyAvVS3ybYpc1EZTZsLidWaYCcO3rbZk72NLskDZUuGd/uNcReAfyp0ujQj NKz44FfuPNdjsb6y7oH5bGBNHAVY0onXv+WdiDaczm8Bhzj+xeRcbOQehHd23cv0pWtU QPlODic9ejrYMfxyv9EDYQvZwBZDIuVcTnr85XkorBVkAbzIzRbV7S7yBKq/WY5Nyceb rwC/LUwUC1SlTmsT3MAEp5KI/2jb4OBPbvx9r0sPwiP0yqRtL9GPc4Pljqd0iKc3cnKD HXfBd9T+YGeIzpFvA/Wm8FbCxbHbDwpmjN2GOkK5ZqJk8P3kLbQVC+TapAxeOevTTLEG /OVw== X-Gm-Message-State: AOJu0YxABFD6csvpv0O9Uorm3xqSAnj9plL3aQz7Dg/1oG8An3UmyC0o UpZHaoSjLhdLRdgyN4FOJba62bkpettmR1niscNNsw== X-Received: by 2002:a67:f754:0:b0:452:7f81:1502 with SMTP id w20-20020a67f754000000b004527f811502mr1905774vso.26.1695925427931; Thu, 28 Sep 2023 11:23:47 -0700 (PDT) MIME-Version: 1.0 References: <20230928092040.9420-1-brgl@bgdev.pl> <20230928092040.9420-3-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Thu, 28 Sep 2023 20:23:36 +0200 Message-ID: Subject: Re: [PATCH v2 02/11] firmware: qcom: scm: add a dedicated SCM memory allocator To: Jeff Johnson Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 11:24:00 -0700 (PDT) On Thu, Sep 28, 2023 at 8:19=E2=80=AFPM Jeff Johnson wrote: > > On 9/28/2023 2:20 AM, Bartosz Golaszewski wrote: > > +void *qcom_scm_mem_alloc(size_t size, gfp_t gfp) > > +{ > > + struct qcom_scm_mem_chunk *chunk; > > + unsigned long vaddr; > > there are places below where you unnecessarily typecast this to its > given type > Ah, it's a leftover from when this variable was of type void *. Thanks. > > + int ret; > > + > > + if (!size) > > + return ZERO_SIZE_PTR; > > + > > + size =3D roundup(size, 1 << PAGE_SHIFT); > > + > > + chunk =3D kzalloc(sizeof(*chunk), gfp); > > + if (!chunk) > > + return NULL; > > + > > + vaddr =3D gen_pool_alloc(qcom_scm_mem.pool, size); > > + if (!vaddr) { > > + kfree(chunk); > > + return NULL; > > + } > > + > > + chunk->paddr =3D gen_pool_virt_to_phys(qcom_scm_mem.pool, > > + (unsigned long)vaddr); > > unnecessary typecast? > > > + chunk->size =3D size; > > + > > + scoped_guard(spinlock_irqsave, &qcom_scm_mem.lock) { > > my first exposure to this infrastructure..very cool now that I've > wrapped my head around it! This helped for those also new to this: > https://lwn.net/Articles/934679/ > It's amazing but be careful with it. I used it wrong in one place and got yelled at by Linus Torvalds personally already. :) Bartosz > > + ret =3D radix_tree_insert(&qcom_scm_mem.chunks, vaddr, ch= unk); > > + if (ret) { > > + gen_pool_free(qcom_scm_mem.pool, (unsigned long)v= addr, > > unnecessary typecast? > > > + chunk->size); > > + kfree(chunk); > > + return NULL; > > + } > > + } > > + > > + return (void *)vaddr; > > +} >