Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Jul 2019 09:36:36 +0000 (UTC)
From:      Andrew Rybchenko <arybchik@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r350370 - head/sys/dev/sfxge/common
Message-ID:  <201907270936.x6R9aa2q093258@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: arybchik
Date: Sat Jul 27 09:36:36 2019
New Revision: 350370
URL: https://svnweb.freebsd.org/changeset/base/350370

Log:
  sfxge(4): fix align to power of 2 when align has smaller type
  
  Substitute driver-defined P2ALIGN() with EFX_P2ALIGN() defined in
  libefx.
  
  Cast value and alignment to one specified type to guarantee result
  correctness.
  
  Reported by:    Andrea Valsania <andrea.valsania at answervad.it>
  Reviewed by:	philip
  Sponsored by:   Solarflare Communications, Inc.
  MFC after:      2 days
  Differential Revision:  https://reviews.freebsd.org/D21075

Modified:
  head/sys/dev/sfxge/common/ef10_rx.c
  head/sys/dev/sfxge/common/efsys.h
  head/sys/dev/sfxge/common/efx.h

Modified: head/sys/dev/sfxge/common/ef10_rx.c
==============================================================================
--- head/sys/dev/sfxge/common/ef10_rx.c	Sat Jul 27 09:36:27 2019	(r350369)
+++ head/sys/dev/sfxge/common/ef10_rx.c	Sat Jul 27 09:36:36 2019	(r350370)
@@ -869,7 +869,7 @@ ef10_rx_qpush(
 	efx_dword_t dword;
 
 	/* Hardware has alignment restriction for WPTR */
-	wptr = P2ALIGN(added, EF10_RX_WPTR_ALIGN);
+	wptr = EFX_P2ALIGN(unsigned int, added, EF10_RX_WPTR_ALIGN);
 	if (pushed == wptr)
 		return;
 

Modified: head/sys/dev/sfxge/common/efsys.h
==============================================================================
--- head/sys/dev/sfxge/common/efsys.h	Sat Jul 27 09:36:27 2019	(r350369)
+++ head/sys/dev/sfxge/common/efsys.h	Sat Jul 27 09:36:36 2019	(r350370)
@@ -88,10 +88,6 @@ extern "C" {
 #define	IS_P2ALIGNED(v, a)	((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
 #endif
 
-#ifndef P2ALIGN
-#define	P2ALIGN(_x, _a)		((_x) & -(_a))
-#endif
-
 #ifndef IS2P
 #define	ISP2(x)			(((x) & ((x) - 1)) == 0)
 #endif

Modified: head/sys/dev/sfxge/common/efx.h
==============================================================================
--- head/sys/dev/sfxge/common/efx.h	Sat Jul 27 09:36:27 2019	(r350369)
+++ head/sys/dev/sfxge/common/efx.h	Sat Jul 27 09:36:36 2019	(r350370)
@@ -60,6 +60,10 @@ extern "C" {
 #define	EFX_P2ROUNDUP(_type, _value, _align)	\
 	(-(-(_type)(_value) & -(_type)(_align)))
 
+/* Align value down to the nearest power of two. */
+#define	EFX_P2ALIGN(_type, _value, _align)	\
+	((_type)(_value) & -(_type)(_align))
+
 /* Return codes */
 
 typedef __success(return == 0) int efx_rc_t;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907270936.x6R9aa2q093258>