Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2205754iof; Tue, 7 Jun 2022 23:10:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztH+UkL6sTDKV+71Z8v8e2lzFvPEgW+Z/WkHVZKumfaLzdoDbvZo/Vda95pgUjZFaYdTdE X-Received: by 2002:a63:b24a:0:b0:3db:b454:b5a with SMTP id t10-20020a63b24a000000b003dbb4540b5amr28190093pgo.312.1654668625745; Tue, 07 Jun 2022 23:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668625; cv=none; d=google.com; s=arc-20160816; b=QQOlD9ldW5y32h55oEiQ9BGh34GLffQtpHaW7JGZsZH3arRy5HZsOF4qlbcTTnYayL Gvw/C/uEwPBUc7d+6A/clrODHBYl8P4kbWnMF3TiiQLCIc9q/PMyx3yqHgZ840a0PNxf 36z1woNc60f+6z4f1rk+zGRpIzUWhoLXTHWSoY43fN+PQ5NRalLUUCyVyiGd175ldaZB IrFbNaYTq+4xxU2w3bY6WlbzYmdboSPtseOn7rcJjuPeIuvlRI9B6vBtZLGN8BvtfFrS bqXSW/y5tKyzdpKJAo6QSjG100HuEYMjVC9e3wfZpeCWUReBT1jQ2QT7gGANZaT1rFEX yCtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cQYgmtim7fNLW2rQnzQUmv/nYd4Qs3yKJEmajjR4FZI=; b=0x+Cx0+VAeeUH5BpO14OpdJWmvAQ9blp+PIY8yaX2FIoTdBIyxfuuaMp0DuwRM8sa6 Kh3kZcvdBUJTzLGmdSfBzZTvgROsuaJX/rI9GEyfi+HoSbr+RavZRrZPhgCo+cVwAb92 AeXa73bDmqtIXuMZrLvGUULm7sIvL9R+83WHBEiFerw1eh5lNHRIVvVk0Y7kJ6FbwxUG zt9gBa7Cm5nj57of2/kal/2E9eO7LJpxwPWKsdsHXSUljx5cqx8S8iKjkaFu/+U36GAr E4qcAUej45lmCOx1ZDyRMFipsiEyZHQinAx1EVDoKeMfmDBU8Ew4Xl8O8qyAu0yJqrBq g6xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xaMuPk5p; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 19-20020a170902e9d300b0016184b32d35si25246628plk.174.2022.06.07.23.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:10:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xaMuPk5p; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52C5D4AADDC; Tue, 7 Jun 2022 22:32:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386376AbiFHBgp (ORCPT + 99 others); Tue, 7 Jun 2022 21:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383465AbiFGVxN (ORCPT ); Tue, 7 Jun 2022 17:53:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54079244F47; Tue, 7 Jun 2022 12:11:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3CF086187F; Tue, 7 Jun 2022 19:11:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 451FEC385A2; Tue, 7 Jun 2022 19:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629105; bh=BVS30Ri3Nw0GyaQoY80jOTh/+gVIBSzugnPkzKzAh24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xaMuPk5pOpxrTEexXjKaUt80PHggnRBkR6JnmhYWGbQTg/clWV+jfC4OSkhfHmcCQ yPK1G3JgtBIAnKtnwaWt8vXTkKQwNLl/Y89JvyJJmNutP9GZUvz+X9su8+MZN4RO5K qPMp2JtdqWwWoJnG+YzyW0WsYib48fiW7HNUlBI4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladis Dronov , Herbert Xu , Sasha Levin Subject: [PATCH 5.18 571/879] hwrng: cn10k - Optimize cn10k_rng_read() Date: Tue, 7 Jun 2022 19:01:29 +0200 Message-Id: <20220607165019.430259307@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladis Dronov [ Upstream commit 753d6770879894de10d74b437ab99ea380f1cad7 ] This function assumes that sizeof(void) is 1 and arithmetic works for void pointers. This is a GNU C extention and may not work with other compilers. Change this by using an u8 pointer. Also move cn10k_read_trng() out of a loop thus saving some cycles. Fixes: 38e9791a0209 ("hwrng: cn10k - Add random number generator support") Signed-off-by: Vladis Dronov Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/char/hw_random/cn10k-rng.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/char/hw_random/cn10k-rng.c b/drivers/char/hw_random/cn10k-rng.c index 35001c63648b..dd226630b67d 100644 --- a/drivers/char/hw_random/cn10k-rng.c +++ b/drivers/char/hw_random/cn10k-rng.c @@ -90,6 +90,7 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data, { struct cn10k_rng *rng = (struct cn10k_rng *)hwrng->priv; unsigned int size; + u8 *pos = data; int err = 0; u64 value; @@ -102,17 +103,20 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data, while (size >= 8) { cn10k_read_trng(rng, &value); - *((u64 *)data) = (u64)value; + *((u64 *)pos) = value; size -= 8; - data += 8; + pos += 8; } - while (size > 0) { + if (size > 0) { cn10k_read_trng(rng, &value); - *((u8 *)data) = (u8)value; - size--; - data++; + while (size > 0) { + *pos = (u8)value; + value >>= 8; + size--; + pos++; + } } return max - size; -- 2.35.1