Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5871896pxu; Thu, 22 Oct 2020 13:15:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNA5icadkmsz+buYgYfgTkmKW2g/Va+lxG+X6mRzYw/ToplFIrpwnG6QcSwX54SumZNgHI X-Received: by 2002:a17:907:20d9:: with SMTP id qq25mr3947606ejb.149.1603397744488; Thu, 22 Oct 2020 13:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603397744; cv=none; d=google.com; s=arc-20160816; b=cXNzMfs/4QmpHZVnGELGj/LdahGyJ27KSCxd8T9VlCVtts84ei0j4bLpkpBzsSPNSp aKP9EgfwG8MjyUZ8TyVEd5wNyjiJUi7DfWSI2RgSmrcdapuPs772LhGVEyOcuPxkqmSZ S/pJshAmijmOb7AfX+7dpJKolz5MWPZt1mbYhCSgyy4ek5Z6RmnnY8v4EmLVnkEONCAC 7vY/RvrwOZeAZtfdcha4WRdIe8IewhJNnjWLeVOEzRugdj87os6oscQtMw5dpOCuukXE u5aIoyM3XpUUMoQ6roOlRBFXJSoL7DK4WdJai2wLGOVy5IzJpf88tU7r1m4dYYgUNgvi bytw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yTl8+Dyvrrb2/Dw69EXXgAneFBqPnAI/YfkWw2WmlZ0=; b=0umHLkW+aLqGogZGD2WVIYkdgQWAMsualb/he8acZg+phNRg1f3te+tEqdHxsk2baf YfUXExjXMOde2jvpStxJY0pUmeT0uuL/cePzze450kKtLB4T7fjJHZSFzZD7jE9AL4If WFXcPqczxnLwW80KQ0ku/7d0/ek4Ejj+kjUSnyx1ccusoHxHWWGq5u7idWAJ6opOQskS 4+6/1mz3KzKfH+CrgZ4L6w/ukSrRk41R9B+vD9h232fQ9dSk8DSOZmnG3swiZLNwd0eZ mbvVuDk8VEVm3ZRKIy/g5eacCWAMSS/OlLOLd8mDQQ0FGTgikAmh3cYX0c6wxXrhQZ77 8HxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TP3rmRat; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t18si1550097eje.652.2020.10.22.13.15.22; Thu, 22 Oct 2020 13:15:44 -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=@gmail.com header.s=20161025 header.b=TP3rmRat; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S367981AbgJVNtu (ORCPT + 99 others); Thu, 22 Oct 2020 09:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S367975AbgJVNtt (ORCPT ); Thu, 22 Oct 2020 09:49:49 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29549C0613CE; Thu, 22 Oct 2020 06:49:48 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id kk5so1014172pjb.1; Thu, 22 Oct 2020 06:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=yTl8+Dyvrrb2/Dw69EXXgAneFBqPnAI/YfkWw2WmlZ0=; b=TP3rmRataYjyPqJdaBoyWz54I2agvdRkJv3SFqJTSNmQk/xR5db1xz/iZBa8eQocpP us2f6rRY4/PFR9V69DZrktfGGiZS240dDh7rOHEqfaOFNEVPDm770MxoDX9s83Tb2NTe tncNTKu71aZNmUgswujzD9aWUenusMFZAfmyztX72I9KTMlT99aA5MT0YbePiggIcpBQ 9b4j1+IGJDYhdz/ICX4s9ljeVTe940faL/Df2j135mNkxF78d0X+YRm/7JTroTM8QrMN M/LPw9ZZYbuNwOgKdeVBP8LKx43c8L2Xkb/ZxqJev5LZfVU/mi7BcbSyxQ8hkxfeqdOG 7HsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=yTl8+Dyvrrb2/Dw69EXXgAneFBqPnAI/YfkWw2WmlZ0=; b=E2PiHxC5pmxwdpsaq04rk+3cd33jddzW8TxJdQ5wYJ0jUh1IKWaujlzSNE35XTxss9 sRFPp+iiBkenff+C/6tFF/WF9ScZiOXhfDvC0b/TvwBex/Dpo5r846r6Q538hkzJKa5t dShVYNQRbXFbhGvUS7QaUiFIAkfOqvqKV3NB/vEZSHr1hQcQwaQ9CVHv4NtoEkr7bWVa iZEhPJwzjSbuQBvp/jcurCD7pbTerEtILm007iVUU+Xabo0IpFbKKWRy9Mg8g3fFa9v0 ZarlOo9/5dmcSnvgEJC4xqcxT64BjSKh3oGxYuxpuitQYgmYJaC85U5mhO6p7vBgFlZV u6/Q== X-Gm-Message-State: AOAM532dj4ahTJxKh0axMg3ZW2bb4rnpw1VwMLLk0jXu6MPR1qeoQBGI 417Vyq31QNgRnN5gWKGYAQE= X-Received: by 2002:a17:902:a383:b029:d5:dde6:2e86 with SMTP id x3-20020a170902a383b02900d5dde62e86mr2562630pla.37.1603374587755; Thu, 22 Oct 2020 06:49:47 -0700 (PDT) Received: from adolin ([49.207.204.75]) by smtp.gmail.com with ESMTPSA id 78sm2479155pfz.211.2020.10.22.06.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:49:47 -0700 (PDT) Date: Thu, 22 Oct 2020 19:19:42 +0530 From: Sumera Priyadarsini To: dri-devel@lists.freedesktop.org Cc: outreachy-kernel@googlegroups.com, alexander.deucher@amd.com, christian.koenig@amd.com, airlied@linux.ie, daniel@ffwll.ch, melissa.srw@gmail.com, linux-media@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. Modify amdgpu_ras.c to use sysfs_emit() instead which knows the size of the temporary buffer. Issue found with Coccinelle. Signed-off-by: Sumera Priyadarsini --- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c index e5ea14774c0c..6d9901e1b4b0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -429,13 +429,13 @@ static ssize_t amdgpu_ras_sysfs_read(struct device *dev, }; if (!amdgpu_ras_get_error_query_ready(obj->adev)) - return snprintf(buf, PAGE_SIZE, + return sysfs_emit(buf, PAGE_SIZE, "Query currently inaccessible\n"); if (amdgpu_ras_error_query(obj->adev, &info)) return -EINVAL; - return snprintf(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n", + return sysfs_emit(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n", "ue", info.ue_count, "ce", info.ce_count); } -- 2.25.1