Re: passwd(1) does not need librpcsvc

2022-01-27 Thread Benjamin Baier
On Thu, 27 Jan 2022 15:17:01 +
Miod Vallat  wrote:

> > Hi,
> > 
> > linking with librpcsvc should be superfluous now.
> 
> Then you should also update DPADD to remove $(LIBRPCSVC}...
> 
Patch V2

Index: Makefile
===
RCS file: /var/cvs/src/usr.bin/passwd/Makefile,v
retrieving revision 1.41
diff -u -p -r1.41 Makefile
--- Makefile26 Nov 2015 19:01:47 -  1.41
+++ Makefile27 Jan 2022 16:20:05 -
@@ -6,8 +6,8 @@ PROG=   passwd
 SRCS=  local_passwd.c passwd.c getpwent.c \
pwd_check.c
 .PATH:  ${.CURDIR}/../../lib/libc/gen
-DPADD+= ${LIBRPCSVC} ${LIBUTIL}
-LDADD+= -lrpcsvc -lutil
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
 CFLAGS+= -I${.CURDIR}
 
 CFLAGS+=-I${.CURDIR}/../../lib/libc/include



passwd(1) does not need librpcsvc

2022-01-27 Thread Benjamin Baier
Hi,

linking with librpcsvc should be superfluous now.

Index: Makefile
===
RCS file: /var/cvs/src/usr.bin/passwd/Makefile,v
retrieving revision 1.41
diff -u -p -r1.41 Makefile
--- Makefile26 Nov 2015 19:01:47 -  1.41
+++ Makefile27 Jan 2022 14:59:09 -
@@ -7,7 +7,7 @@ SRCS=   local_passwd.c passwd.c getpwent.c
pwd_check.c
 .PATH:  ${.CURDIR}/../../lib/libc/gen
 DPADD+= ${LIBRPCSVC} ${LIBUTIL}
-LDADD+= -lrpcsvc -lutil
+LDADD+= -lutil
 CFLAGS+= -I${.CURDIR}
 
 CFLAGS+=-I${.CURDIR}/../../lib/libc/include

--
Greetings Ben



Re: possible memory leak in ipmi get_sdr

2022-01-14 Thread Benjamin Baier
On Fri, 14 Jan 2022 09:25:53 +0100
Moritz Buhl  wrote:

> I thought I'd walk through my understanding of the code
> to make it easier to review.
> 
> from sys/dev/ipmi.c:
> 
> 1019 int
> 1020 get_sdr(struct ipmi_softc *sc, u_int16_t recid, u_int16_t *nxtrec)
> 1021 {
> ...
> 1046 psdr = malloc(sdrlen, M_DEVBUF, M_NOWAIT);
> 1047 if (psdr == NULL)
> 1048 return (1);
> Now psdr is allocated. In the following loop it is freed correctly on
> failure:
> 1062 free(psdr, M_DEVBUF, sdrlen);
> 1063 return (1);
> If everything works, we attach it to a list:
> 1067 /* Add SDR to sensor list, if not wanted, free buffer */
> 1068 if (add_sdr_sensor(sc, psdr, sdrlen) == 0)
> 1069 free(psdr, M_DEVBUF, sdrlen);
> 1070
> 1071 return (0);
> So if add_sdr_sensor doesn't return 0 it has to keep a reference
> to psdr somewhere.
> 
> 1335 int
> 1336 add_sdr_sensor(struct ipmi_softc *sc, u_int8_t *psdr, int sdrlen)
> 1337 {
> There are two switch cases that both call add_child_sensors and set
> rc with it, if no previous failures occour:
> 1349 rc = add_child_sensors(sc, psdr, 1, s1->sensor_num,
> 1350 s1->sensor_type, s1->event_code, 0, s1->entity_id, 
> name);
> 1351 break;
> and
> 1358 rc = add_child_sensors(sc, psdr, s2->share1 & 0xF,
> 1359 s2->sensor_num, s2->sensor_type, s2->event_code,
> 1360 s2->share2 & 0x7F, s2->entity_id, name);
> 1361 break;
> These two calls are the only locations that can make add_sdr_sensor
> return something else than 0.
> 
> 1370 int
> 1371 add_child_sensors(struct ipmi_softc *sc, u_int8_t *psdr, int count,
> 1372 int sensor_num, int sensor_type, int ext_type, int sensor_base,
> 1373 int entity, const char *name)
> 1374 {
> So as mentioned before, this function needs to return 0 or keep a
> reference to  psdr.
> This is not the case in two situations, but to keep it simple I
> will only show one:
> 1388 psensor = malloc(sizeof(*psensor), M_DEVBUF, M_NOWAIT | 
> M_ZERO);
> 1389 if (psensor == NULL)
> 1390 break;
> ...
> 1420 return (1);
> 
> I hope this helps
> mbuhl
> 

Hi, llvm/scan-build agrees.
http://www.netzbasis.de/openbsd/scan-build/kernel/2022-01-12-131800-47421-1/report-c7382e.html#EndPath

Patch seems correct, but I'm not a dev and I don't have the hardware eighter.

Greetings Ben



Re: update xf86-video-amdgpu to latest git

2021-07-31 Thread Benjamin Baier
On Thu, 8 Jul 2021 17:29:01 +1000
Jonathan Gray  wrote:

> The latest xf86-video-amdgpu release was in 2019.
> 
> xf86-video-amdgpu-19.1.0..origin/master
> 
> minus commits we already have
> cb27a5b Handle NULL fb_ptr in pixmap_get_fb
> e2cd67a Bail from amdgpu_pixmap_get_handle with ShadowFB
> edcbe5f Fix link failure with gcc 10
> 
> With a X_PRIVSEP path added to amdgpu_probe.c to handle the change from
> drmOpen() to open().

Works great. I do get a much stabler X experience.

The DRM update to 5.10.* also was great, without regressions so far.
But like with 5.7.* I still get the occassional 
[drm] *ERROR* ring sdma0 timeout, ...
Which userland now handles pretty gracefully with this.

Greetings Ben

OpenBSD 6.9-current (GENERIC.MP) #151: Tue Jul 27 12:18:05 MDT 2021
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 17069760512 (16278MB)
avail mem = 16536481792 (15770MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.2 @ 0x8f1a6000 (94 entries)
bios0: vendor American Megatrends Inc. version "2301" date 07/10/2020
bios0: ASUSTeK COMPUTER INC. ROG STRIX B360-G GAMING
acpi0 at bios0: ACPI 6.1
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT FIDT MCFG WSMT SSDT SSDT SSDT HPET SSDT SSDT 
UEFI LPIT SSDT SSDT DBGP DBG2 DMAR SSDT BGRT
acpi0: wakeup devices PEG0(S4) PEGP(S4) PEG1(S4) PEGP(S4) PEG2(S4) PEGP(S4) 
SIO1(S3) UAR1(S4) RP01(S4) PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) 
RP04(S4) PXSX(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz, 3593.04 MHz, 06-9e-0b
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SRBDS_CTRL,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 24MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz, 3591.64 MHz, 06-9e-0b
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SRBDS_CTRL,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 4 (application processor)
cpu2: Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz, 3591.64 MHz, 06-9e-0b
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SRBDS_CTRL,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 2, package 0
cpu3 at mainbus0: apid 6 (application processor)
cpu3: Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz, 3591.64 MHz, 06-9e-0b
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SRBDS_CTRL,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 0, core 3, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 120 pins
acpimcfg0 at acpi0
acpimcfg0: addr 0xe000, bus 0-255
acpihpet0 at acpi0: 2399 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 1 (PEG0)
acpiprt2 at acpi0: bus -1 (PEG1)
acpiprt3 at acpi0: bus -1 (PEG2)
acpiprt4 at acpi0: bus -1 (RP01)
acpiprt5 at acpi0: bus -1 (RP02)
acpiprt6 at acpi0: bus -1 

Manpage fix: passwd.1

2021-04-14 Thread Benjamin Baier
Hi,

don't mention _PASSWORD_LEN in passwd manpage.
It's also no longer true, since Rev1.52, local_passwd.c uses 1024
bytes for the password array.

Greetings Ben

Index: passwd.1
===
RCS file: /var/cvs/src/usr.bin/passwd/passwd.1,v
retrieving revision 1.46
diff -u -p -r1.46 passwd.1
--- passwd.123 Apr 2019 17:52:12 -  1.46
+++ passwd.114 Apr 2021 08:59:39 -
@@ -51,9 +51,6 @@ The new password must be entered twice t
 .Pp
 The new password should be at least six characters long and not
 purely alphabetic.
-Its total length must be less than
-.Dv _PASSWORD_LEN
-(currently 128 characters).
 A mixture of both lower and uppercase letters, numbers, and
 meta-characters is encouraged.
 .Pp



ksh vi.c: define CTRL locally

2021-03-11 Thread Benjamin Baier
Hi,

lets's sync up vi.c with emacs.c and define CTRL locally.
Makes the portable version work on FreeBSD 
https://github.com/ibara/oksh/issues/59
And as a bonus makes ksh -DSMALL compile with -DVI.

Greetings Ben

Index: vi.c
===
RCS file: /var/cvs/src/bin/ksh/vi.c,v
retrieving revision 1.59
diff -u -p -r1.59 vi.c
--- vi.c10 Mar 2021 20:17:33 -  1.59
+++ vi.c11 Mar 2021 10:13:07 -
@@ -22,6 +22,9 @@
 #include "sh.h"
 #include "edit.h"
 
+#undef CTRL
+#defineCTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F)/* 
ASCII */
+
 struct edstate {
char*cbuf;  /* main buffer to build the command line */
int cbufsize;   /* number of bytes allocated for cbuf */



Re: ksh: [vi.c] "clear-screen" bug + patch

2021-03-09 Thread Benjamin Baier
Ping

On Sat, 21 Nov 2020 18:59:25 +0200
Πάτερος Πέτρος  wrote:

> Hello everyone,
> 
> I am sending this because of an issue I had with a ported version of
> your ksh(1) on Linux (you can find the port at
> https://github.com/ibara/oksh), but everything I say here are also
> tested on a VM running OpenBSD 6.8.
Still an issue on  6.9 GENERIC.MP#379 amd64

> When using the 6.8 version I noticed that (in vi editing mode) hitting
> Ctrl+L (^L) attempts to clear the screen, both in normal and insert
> mode. The problem is that it clears the screen and then it prints
> only the last line of the prompt (PS1). The problem is when a multiline
> PS1 is in use, in which case the prompt is not printed as expected.
I do use a 2-line $PS1 prompt. Ctrl+L works (prints full $PS1) in emacs mode,
does not work correct in vi mode (prints last line of $PS1)

> It seems reasonable to me that this behviour is a bug, so I attempted
> to edit vi.c and came up with the first of the following patches.
Does what it says, with multiline $PS1. Reattached below.
Ramdisk's SMALL version is not affected, because vi mode is not compiled in.

> Also, now there is no way to ask redraw of the wrinting line
> (that is what ^L were doing previously). In normal mode that
> was remapped to ^R. I think that it is useful in insert mode
> also. You can see the second patch for this.
Maybe later?

> I hope that this will at least bring the issue to your attention.
> 
> Thank you for your time.



First patch reattached from a cvs diff
Index: vi.c
===
RCS file: /var/cvs/src/bin/ksh/vi.c,v
retrieving revision 1.57
diff -u -p -r1.57 vi.c
--- vi.c20 Sep 2020 14:40:45 -  1.57
+++ vi.c9 Mar 2021 12:57:30 -
@@ -55,7 +55,7 @@ static intEndword(int);
 static int grabhist(int, int);
 static int grabsearch(int, int, int, char *);
 static voiddo_clear_screen(void);
-static voidredraw_line(int);
+static voidredraw_line(int, int);
 static voidrefresh_line(int);
 static int outofwin(void);
 static voidrewindow(void);
@@ -719,7 +719,7 @@ vi_cmd(int argcnt, const char *cmd)
break;
 
case CTRL('r'):
-   redraw_line(1);
+   redraw_line(1, 0);
break;
 
case '@':
@@ -1737,18 +1737,18 @@ do_clear_screen(void)
neednl = 0;
}
 #endif
-   redraw_line(neednl);
+   redraw_line(neednl, 1);
 }
 
 static void
-redraw_line(int neednl)
+redraw_line(int neednl, int full)
 {
(void) memset(wbuf[win], ' ', wbuf_len);
if (neednl) {
x_putc('\r');
x_putc('\n');
}
-   vi_pprompt(0);
+   vi_pprompt(full);
cur_col = pwidth;
morec = ' ';
 }
@@ -2109,7 +2109,7 @@ complete_word(int command, int count)
vi_error();
x_print_expansions(nwords, words, is_command);
x_free_words(nwords, words);
-   redraw_line(0);
+   redraw_line(0, 0);
return -1;
}
/*
@@ -2183,7 +2183,7 @@ print_expansions(struct edstate *e)
}
x_print_expansions(nwords, words, is_command);
x_free_words(nwords, words);
-   redraw_line(0);
+   redraw_line(0, 0);
return 0;
 }
 

> ### /* first patch */
> diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c
> index 53be5a76d50..5a45ab67710 100644
> --- a/bin/ksh/vi.c
> +++ b/bin/ksh/vi.c
> @@ -55,7 +55,7 @@ static int  Endword(int);
>   static int  grabhist(int, int);
>   static int  grabsearch(int, int, int, char *);
>   static void do_clear_screen(void);
> -static void  redraw_line(int);
> +static void  redraw_line(int, int);
>   static void refresh_line(int);
>   static int  outofwin(void);
>   static void rewindow(void);
> @@ -719,7 +719,7 @@ vi_cmd(int argcnt, const char *cmd)
>   break;
> 
>   case CTRL('r'):
> - redraw_line(1);
> + redraw_line(1, 0);
>   break;
> 
>   case '@':
> @@ -1737,18 +1737,18 @@ do_clear_screen(void)
>   neednl = 0;
>   }
>   #endif
> - redraw_line(neednl);
> + redraw_line(neednl, 1);
>   }
> 
>   static void
> -redraw_line(int neednl)
> +redraw_line(int neednl, int full)
>   {
>   (void) memset(wbuf[win], ' ', wbuf_len);
>   if (neednl) {
>   x_putc('\r');
>   x_putc('\n');
>   }
> - vi_pprompt(0);
> + vi_pprompt(full);
>   cur_col = pwidth;
>   morec = ' ';
>   }
> @@ -2109,7 +2109,7 @@ complete_word(int command, int count)
>   vi_error();
>   x_print_expansions(nwords, words, is_command);
>   x_free_words(nwords, words);
> - 

Throttle inteldrm GPU when CPU is throttled (was [WIP] new sysctl hw.gpuperf)

2021-02-25 Thread Benjamin Baier
, act %d 
MHz\n",
+   min, max, rps->min_freq_softlimit, rps->max_freq_softlimit,
+   rps->boost_freq, intel_gpu_freq(dev_priv, rps->cur_freq));
+
+   return 0;
+}
+#endif /* __OpenBSD__ */
 
 int
 inteldrm_detach(struct device *self, int flags)
Index: dev/pci/drm/i915/i915_drv.h
===
RCS file: /var/cvs/src/sys/dev/pci/drm/i915/i915_drv.h,v
retrieving revision 1.92
diff -u -p -r1.92 i915_drv.h
--- dev/pci/drm/i915/i915_drv.h 29 Jun 2020 04:13:30 -  1.92
+++ dev/pci/drm/i915/i915_drv.h 18 Jul 2020 19:43:06 -
@@ -2000,3 +2000,8 @@ i915_coherent_map_type(struct drm_i915_p
 }
 
 #endif
+
+#ifdef __OpenBSD__
+#include 
+int inteldrm_set_gpuperf(gpuperf_level level, void *arg);
+#endif /* __OpenBSD__ */
Index: kern/sched_bsd.c
===
RCS file: /var/cvs/src/sys/kern/sched_bsd.c,v
retrieving revision 1.63
diff -u -p -r1.63 sched_bsd.c
--- kern/sched_bsd.c30 May 2020 14:42:59 -  1.63
+++ kern/sched_bsd.c18 Jul 2020 19:43:06 -
@@ -540,6 +540,7 @@ int perfpolicy = PERFPOL_MANUAL;
 /*
  * The code below handles CPU throttling.
  */
+#include 
 #include 
 
 void setperf_auto(void *);
@@ -630,6 +631,11 @@ sysctl_hwsetperf(void *oldp, size_t *old
perflevel = newperf;
cpu_setperf(perflevel);
 
+   if (perflevel == 100)
+   gpuperf_set(GPU_HIGH);
+   else
+   gpuperf_set(GPU_LOW);
+
return 0;
 }
 
@@ -674,9 +680,11 @@ sysctl_hwperfpolicy(void *oldp, size_t *
 
if (perfpolicy == PERFPOL_AUTO) {
timeout_add_msec(_to, 200);
+   gpuperf_set(GPU_AUTO);
} else if (perfpolicy == PERFPOL_HIGH) {
perflevel = 100;
cpu_setperf(perflevel);
+   gpuperf_set(GPU_HIGH);
}
return 0;
 }
Index: kern/subr_gpuperf.c
===
RCS file: kern/subr_gpuperf.c
diff -N kern/subr_gpuperf.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ kern/subr_gpuperf.c 18 Jul 2020 19:43:06 -
@@ -0,0 +1,79 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2019, 2020 Benjamin Baier 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#ifdef GPUPERF_DEBUG
+#define DPRINTF(x...) do { printf(x); } while(0)
+#else
+#define DPRINTF(x...)
+#endif /* GPUPERF_DEBUG */
+
+struct gpuperf_dev {
+   char name[16];  /* device name */
+   void *arg;  /* arg passthrough */
+   int (*callback)(gpuperf_level, void *);
+   LIST_ENTRY(gpuperf_dev) next;
+};
+
+LIST_HEAD(, gpuperf_dev) gpuperf_list =
+   LIST_HEAD_INITIALIZER(gpuperf_list);
+
+int
+gpuperf_register(const char *name, int (*callback)(gpuperf_level, void *),
+void *arg)
+{
+   struct gpuperf_dev *dev;
+   int status = 0;
+
+   if ((dev = malloc(sizeof(*dev), M_DEVBUF, M_NOWAIT)) == NULL)
+   return -1;
+
+   strlcpy(dev->name, name, sizeof(dev->name));
+   dev->callback = callback;
+   dev->arg = arg;
+
+   LIST_INSERT_HEAD(_list, dev, next);
+   status = dev->callback(GPU_AUTO, dev->arg);
+
+   DPRINTF("gpuperf: %s registered, status %d\n", dev->name, status);
+
+   return status;
+}
+
+int
+gpuperf_set(gpuperf_level level)
+{
+   struct gpuperf_dev *dev;
+   int status = 0;
+
+   if ((level < GPU_AUTO) || (level > GPU_HIGH))
+   return -1;
+
+   LIST_FOREACH(dev, _list, next) {
+   status += dev->callback(level, dev->arg);
+
+   DPRINTF("gpuperf: requesting %d from %s, status %d\n",
+   level, dev->name, status);
+   }
+
+   return status;
+}
Index: sys/gpuperf.h
===
RCS file: sys/gpuperf.h
diff -N sys/gpuperf.h
--- /dev/null   1 Jan 1970 00:00:00 -
+++ sys/gpuperf.h   18 Jul 2020 19:43:06 -
@@ -0,0 +1,31 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2019, 2020 Benjamin Baier 
+ *
+ * Permission to use, copy, modify, and distribute

malloc.conf and pledge

2021-01-19 Thread Benjamin Baier
Hi,

/etc/malloc.conf is long gone(6.5). Time to remove the special case?

Xenocara is clean.
Base only mentions malloc.conf in a comment in
regress/usr.bin/ssh/connect-privsep.sh.
Ports mention /etc/malloc.conf in an old and unused systrace policy.
Ports with jemalloc should never use /etc/malloc.conf and as I see it
they either disable jemalloc or define a prefix.

Greetings Ben

Index: kern_pledge.c
===
RCS file: /var/cvs/src/sys/kern/kern_pledge.c,v
retrieving revision 1.267
diff -u -p -r1.267 kern_pledge.c
--- kern_pledge.c   29 Oct 2020 21:15:27 -  1.267
+++ kern_pledge.c   18 Jan 2021 22:59:54 -
@@ -719,14 +719,6 @@ pledge_namei(struct proc *p, struct name
}
 
break;
-   case SYS_readlink:
-   /* Allow /etc/malloc.conf for malloc(3). */
-   if ((ni->ni_pledge == PLEDGE_RPATH) &&
-   strcmp(path, "/etc/malloc.conf") == 0) {
-   ni->ni_cnd.cn_flags |= BYPASSUNVEIL;
-   return (0);
-   }
-   break;
case SYS_stat:
/* DNS needs /etc/resolv.conf. */
if ((ni->ni_pledge == PLEDGE_RPATH) &&



Re: fix off by one in amdgpu_vm_handle_fault

2020-11-12 Thread Benjamin Baier
On Fri, 13 Nov 2020 00:16:12 +1100
Jonathan Gray  wrote:

> On Thu, Nov 12, 2020 at 01:48:05PM +0100, Benjamin Baier wrote:
> > Hi
> > 
> > this fixes the VM_L2_PROTECTION_FAULT_STATUS I was getting.
> > (and maybe also some of the bug reports, reporting L2 protection faults)
> > It was reproduceable by running
> > piglit run quick -t "spec@glsl-1.30@execution@texelfetch fs sampler2d 
> > 1x281-501x281" out
> 
> Are you sure you see this without that change?  There were changes to
> the ttm page fault handling in October which resolved it here.
Indeed, seems I screwed up A-B testing.

Patch still seems relevant (for correctnes sake) but I do need to do
more research.

> > 
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR* [gfxhub0] no-retry page 
> > > fault (src_id:0 ring:136 vmid:3 pasid:32820, for process  pid 0 thread 
> > > texelFetch pid 12232)
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR*   in page starting at 
> > > address 0x80011138a000 from client 27
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR* 
> > > VM_L2_PROTECTION_FAULT_STATUS:0x003C0111
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR*MORE_FAULTS: 0x1
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR*WALKER_ERROR: 0x0
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR*PERMISSION_FAULTS: 0x1
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR*MAPPING_ERROR: 0x1
> > > drm:pid57901:gmc_v9_0_process_interrupt *ERROR*RW: 0x1
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR* [gfxhub0] retry page 
> > > fault (src_id:0 ring:0 vmid:3 pasid:32820, for process  pid 0 thread 
> > > texelFetch pid 12232)
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*   in page starting at 
> > > address 0x80011138 from client 27
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR* 
> > > VM_L2_PROTECTION_FAULT_STATUS:0x003C0071
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*MORE_FAULTS: 0x1
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*WALKER_ERROR: 0x0
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*PERMISSION_FAULTS: 0x7
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*MAPPING_ERROR: 0x0
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*RW: 0x1
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR* [gfxhub0] no-retry page 
> > > fault (src_id:0 ring:152 vmid:3 pasid:32820, for process  pid 0 thread 
> > > texelFetch pid 12232)
> > > drm:pid15167:gmc_v9_0_process_interrupt *ERROR*   in page starting at 
> > > address 0x800111384000 from client 27
> > 
> > jsg@, kettenis@ an me had some private mails about this a while back
> > and I finally found a cure here: 
> > https://cgit.freedesktop.org/~agd5f/linux/commit/?h=amd-drm-next-5.11-2020-11-05=19201c075d2ca6a58421aa1f22281977e84ae17f
> > 
> > Greetings Ben
> > 
> > Index: amdgpu_vm.c
> > ===
> > RCS file: /var/cvs/src/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c,v
> > retrieving revision 1.9
> > diff -u -p -r1.9 amdgpu_vm.c
> > --- amdgpu_vm.c 13 Jul 2020 06:25:17 -  1.9
> > +++ amdgpu_vm.c 11 Nov 2020 16:51:37 -
> > @@ -3434,7 +3434,7 @@ bool amdgpu_vm_handle_fault(struct amdgp
> > value = 0;
> > }
> >  
> > -   r = amdgpu_vm_bo_update_mapping(adev, vm, true, NULL, addr, addr + 1,
> > +   r = amdgpu_vm_bo_update_mapping(adev, vm, true, NULL, addr, addr,
> > flags, value, NULL, NULL);
> > if (r)
> > goto error_unlock;
> > 
> > 
> > ---
> > 
> > OpenBSD 6.8-current (GENERIC.MP) #11: Wed Nov 11 22:26:53 CET 2020
> > b...@fox.netzbasis.de:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> > real mem = 17078054912 (16286MB)
> > avail mem = 16545169408 (15778MB)
> > random: good seed from bootblocks
> > mpath0 at root
> > scsibus0 at mpath0: 256 targets
> > mainbus0 at root
> > bios0 at mainbus0: SMBIOS rev. 3.2 @ 0x8f19e000 (94 entries)
> > bios0: vendor American Megatrends Inc. version "2002" date 06/18/2020
> > bios0: ASUSTeK COMPUTER INC. ROG STRIX B360-G GAMING
> > acpi0 at bios0: ACPI 6.1
> > acpi0: sleep states S0 S3 S4 S5
> > acpi0: tables DSDT FACP APIC FPDT FIDT MCFG WSMT SSDT SSDT SSDT HPET SSDT 
> > SSDT UEFI LPIT SSDT SSDT DBGP DBG2 SSDT BGRT
> > acpi0: wakeup devices PEG0(S4) PEGP(S4) PEG1(S4) PEGP(S4) PEG2(S4) PEGP(S4) 
> > SIO1(S3) UAR1(S4) RP01(S4) P

fix off by one in amdgpu_vm_handle_fault

2020-11-12 Thread Benjamin Baier
Hi

this fixes the VM_L2_PROTECTION_FAULT_STATUS I was getting.
(and maybe also some of the bug reports, reporting L2 protection faults)
It was reproduceable by running
piglit run quick -t "spec@glsl-1.30@execution@texelfetch fs sampler2d 
1x281-501x281" out

> drm:pid57901:gmc_v9_0_process_interrupt *ERROR* [gfxhub0] no-retry page fault 
> (src_id:0 ring:136 vmid:3 pasid:32820, for process  pid 0 thread texelFetch 
> pid 12232)
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR*   in page starting at address 
> 0x80011138a000 from client 27
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR* 
> VM_L2_PROTECTION_FAULT_STATUS:0x003C0111
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR*MORE_FAULTS: 0x1
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR*WALKER_ERROR: 0x0
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR*PERMISSION_FAULTS: 0x1
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR*MAPPING_ERROR: 0x1
> drm:pid57901:gmc_v9_0_process_interrupt *ERROR*RW: 0x1
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR* [gfxhub0] retry page fault 
> (src_id:0 ring:0 vmid:3 pasid:32820, for process  pid 0 thread texelFetch pid 
> 12232)
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*   in page starting at address 
> 0x80011138 from client 27
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR* 
> VM_L2_PROTECTION_FAULT_STATUS:0x003C0071
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*MORE_FAULTS: 0x1
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*WALKER_ERROR: 0x0
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*PERMISSION_FAULTS: 0x7
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*MAPPING_ERROR: 0x0
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*RW: 0x1
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR* [gfxhub0] no-retry page fault 
> (src_id:0 ring:152 vmid:3 pasid:32820, for process  pid 0 thread texelFetch 
> pid 12232)
> drm:pid15167:gmc_v9_0_process_interrupt *ERROR*   in page starting at address 
> 0x800111384000 from client 27

jsg@, kettenis@ an me had some private mails about this a while back
and I finally found a cure here: 
https://cgit.freedesktop.org/~agd5f/linux/commit/?h=amd-drm-next-5.11-2020-11-05=19201c075d2ca6a58421aa1f22281977e84ae17f

Greetings Ben

Index: amdgpu_vm.c
===
RCS file: /var/cvs/src/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c,v
retrieving revision 1.9
diff -u -p -r1.9 amdgpu_vm.c
--- amdgpu_vm.c 13 Jul 2020 06:25:17 -  1.9
+++ amdgpu_vm.c 11 Nov 2020 16:51:37 -
@@ -3434,7 +3434,7 @@ bool amdgpu_vm_handle_fault(struct amdgp
value = 0;
}
 
-   r = amdgpu_vm_bo_update_mapping(adev, vm, true, NULL, addr, addr + 1,
+   r = amdgpu_vm_bo_update_mapping(adev, vm, true, NULL, addr, addr,
flags, value, NULL, NULL);
if (r)
goto error_unlock;


---

OpenBSD 6.8-current (GENERIC.MP) #11: Wed Nov 11 22:26:53 CET 2020
b...@fox.netzbasis.de:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 17078054912 (16286MB)
avail mem = 16545169408 (15778MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.2 @ 0x8f19e000 (94 entries)
bios0: vendor American Megatrends Inc. version "2002" date 06/18/2020
bios0: ASUSTeK COMPUTER INC. ROG STRIX B360-G GAMING
acpi0 at bios0: ACPI 6.1
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT FIDT MCFG WSMT SSDT SSDT SSDT HPET SSDT SSDT 
UEFI LPIT SSDT SSDT DBGP DBG2 SSDT BGRT
acpi0: wakeup devices PEG0(S4) PEGP(S4) PEG1(S4) PEGP(S4) PEG2(S4) PEGP(S4) 
SIO1(S3) UAR1(S4) RP01(S4) PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) 
RP04(S4) PXSX(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz, 3593.43 MHz, 06-9e-0b
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SRBDS_CTRL,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 24MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz, 3591.64 MHz, 06-9e-0b
cpu1: 

Fw: Hardware UUID discrepancies (dmidecode vs. sysctl) on amd64 multiboot system

2020-11-08 Thread Benjamin Baier
Forwarding to tech@ by request from  Stuart Henderson
This issue came up on misc@
https://marc.info/?l=openbsd-misc=160477082230840=2

Begin forwarded message:

Date: Sat, 7 Nov 2020 22:30:44 +0100
From: Benjamin Baier 
To: Bruce Lilly 
Cc: m...@openbsd.org
Subject: Re: Hardware UUID discrepancies (dmidecode vs. sysctl) on amd64 
multiboot system


On Sat, 7 Nov 2020 12:36:42 -0500
Bruce Lilly  wrote:

> I have a multiboot system with several OSes on the same hardware.
> 
> Summary: OpenBSD UUID reported by dmidecode and from sysctl differ
> significantly w.r.t. byte ordering.  Multiple OSes report the same dmidecode
> UUID, and most other OSes provide one or more alternate ways of accessing
> the UUID which yields results consistent with dmidecode.
> 
> Details:
> dmidecode (after fiddling with kern.allowkmem via /etc/sysctl.conf on OpenBSD)
> run on each OS that has a dmidecode utility reports the same hardware UUID
> (modulo hexadecimal digit case), viz.
> 
> UUID: 484B1340-D7AA-81E5-3CED-9C5C8E3D6756
> 
> OpenBSD (6.8) `sysctl hw.uuid` instead reports:
> 
> hw.uuid=40134b48-aad7-e581-3ced-9c5c8e3d6756
> 
> Note that the differences are:
> 1. case of hexadecimal digits (inconsequential)
> 2. byte ordering (but inconsistently so between the initial part
> and the last 64 bits (the latter part's byte ordering is consistent
> with dmidecode))
> 
According to SMBIOS Reference Specification, you are correct.
  7.2.1
  Although RFC 4122 recommends network byte order for all fields, the PC 
industry (including the ACPI,
  UEFI, and Microsoft specifications) has consistently used little-endian byte 
encoding for the first three
  fields: time_low, time_mid, time_hi_and_version. The same encoding, also 
known as wire format, should
  also be used for the SMBIOS representation of the UUID.
  The UUID {00112233-4455-6677-8899-AABBCCDDEEFF} would thus be represented as:
  33 22 11 00 55 44 77 66 88 99 AA BB CC DD EE FF.

What are the ramifications of a changed UUID?
What software depends on hw.uuid not changing? 

Greetings Ben

---

Index: amd64/amd64/bios.c
===
RCS file: /var/cvs/src/sys/arch/amd64/amd64/bios.c,v
retrieving revision 1.43
diff -u -p -r1.43 bios.c
--- amd64/amd64/bios.c  26 Aug 2020 03:29:05 -  1.43
+++ amd64/amd64/bios.c  7 Nov 2020 20:58:51 -
@@ -501,9 +501,9 @@ smbios_info(char *str)
if (hw_uuid) {
snprintf(hw_uuid, SMBIOS_UUID_REPLEN,
SMBIOS_UUID_REP,
-   sys->uuid[0], sys->uuid[1], sys->uuid[2],
-   sys->uuid[3], sys->uuid[4], sys->uuid[5],
-   sys->uuid[6], sys->uuid[7], sys->uuid[8],
+   sys->uuid[3], sys->uuid[2], sys->uuid[1],
+   sys->uuid[0], sys->uuid[5], sys->uuid[4],
+   sys->uuid[7], sys->uuid[6], sys->uuid[8],
sys->uuid[9], sys->uuid[10], sys->uuid[11],
sys->uuid[12], sys->uuid[13], sys->uuid[14],
sys->uuid[15]);
Index: arm64/dev/smbios.c
===
RCS file: /var/cvs/src/sys/arch/arm64/dev/smbios.c,v
retrieving revision 1.6
diff -u -p -r1.6 smbios.c
--- arm64/dev/smbios.c  26 Aug 2020 03:29:05 -  1.6
+++ arm64/dev/smbios.c  7 Nov 2020 21:00:32 -
@@ -410,9 +410,9 @@ smbios_info(char *str)
if (hw_uuid) {
snprintf(hw_uuid, SMBIOS_UUID_REPLEN,
SMBIOS_UUID_REP,
-   sys->uuid[0], sys->uuid[1], sys->uuid[2],
-   sys->uuid[3], sys->uuid[4], sys->uuid[5],
-   sys->uuid[6], sys->uuid[7], sys->uuid[8],
+   sys->uuid[3], sys->uuid[2], sys->uuid[1],
+   sys->uuid[0], sys->uuid[5], sys->uuid[4],
+   sys->uuid[7], sys->uuid[6], sys->uuid[8],
sys->uuid[9], sys->uuid[10], sys->uuid[11],
sys->uuid[12], sys->uuid[13], sys->uuid[14],
sys->uuid[15]);
Index: i386/i386/bios.c
===
RCS file: /var/cvs/src/sys/arch/i386/i386/bios.c,v
retrieving revision 1.126
diff -u -p -r1.126 bios.c
--- i386/i386/bios.c26 Aug 2020 03:29:05 -  1.126
+++ i386/i386/bios.c7 Nov 202

Adapt usbhidaction.1 example to sndio changes

2020-06-23 Thread Benjamin Baier
Hi,

adapt usbhidaction.1 example to sndio changes.

Greetings Ben

Index: usbhidaction.1
===
RCS file: /var/cvs/src/usr.bin/usbhidaction/usbhidaction.1,v
retrieving revision 1.14
diff -u -p -r1.14 usbhidaction.1
--- usbhidaction.1  20 Apr 2020 20:54:31 -  1.14
+++ usbhidaction.1  23 Jun 2020 12:06:01 -
@@ -105,20 +105,20 @@ master volume and muting of an
 .Xr azalia 4
 device using the multimedia keys on a Belkin USB keyboard.
 .Bd -literal -offset indent
-# The volume range is 0..255. Moving 8 volume steps each keypress
+# The volume range is 0..1. Moving 0.05 volume steps each keypress
 # moves quickly through the volume range but still has decent
 # granularity.
 Consumer:Volume_Increment 1
-   mixerctl -f $1 outputs.master=+8
+   sndioctl -f $1 output.level=+0.05
 Consumer:Volume_Decrement 1
-   mixerctl -f $1 outputs.master=-8
+   sndioctl -f $1 output.level=-0.05
 Consumer:Mute 1
-   mixerctl -f $1 outputs.master.mute=toggle
+   sndioctl -f $1 output.mute=!
 .Ed
 .Pp
 A sample invocation using this configuration would be
 .Bd -literal -offset indent
-$ usbhidaction -f /dev/uhid1 -c conf /dev/audioctl0
+$ usbhidaction -f /dev/uhid1 -c conf snd/0
 .Ed
 .Sh SEE ALSO
 .Xr usbhidctl 1 ,



Re: Some redundant code lines in sys

2020-06-05 Thread Benjamin Baier
On Fri, 5 Jun 2020 12:56:21 +0200
"Prof. Dr. Steffen Wendzel"  wrote:

> Dear all:
> 
> just in case this appears useful to you: I found some redundant code
> lines in the following files.
> 
> sys/net/pipex.h:
>struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
>struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
> 
> usr.sbin/relayd/agentx.c
>snmp_agentx_oid(pdu, oid) == -1 ||
>snmp_agentx_oid(pdu, oid) == -1 ||
> 
> usr.sbin/snmpd/agentx.c:
>  snmp_agentx_oid(pdu, oid) == -1 ||
>  snmp_agentx_oid(pdu, oid) == -1 ||
> 
> usr.sbin/bgpd/rde.h:
>   void path_init(u_int32_t);
>   void path_init(u_int32_t);
> 
> lib/libcurses/nc_tparm.h:
> #define TPARM_1(a,b) TPARM_2(a,b,0)
> #define TPARM_1(a,b) TPARM_2(a,b,0)
> 
> Kind regards,
> Steffen
> 

Interesting enought to spend a few minutes on it :-)

Index: lib/libcurses/nc_tparm.h
===
RCS file: /cvs/src/lib/libcurses/nc_tparm.h,v
retrieving revision 1.1
diff -u -p -r1.1 nc_tparm.h
--- lib/libcurses/nc_tparm.h12 Jan 2010 23:21:59 -  1.1
+++ lib/libcurses/nc_tparm.h5 Jun 2020 12:15:42 -
@@ -62,6 +62,5 @@
 #define TPARM_3(a,b,c,d) TPARM_4(a,b,c,d,0)
 #define TPARM_2(a,b,c) TPARM_3(a,b,c,0)
 #define TPARM_1(a,b) TPARM_2(a,b,0)
-#define TPARM_1(a,b) TPARM_2(a,b,0)
 #define TPARM_0(a) TPARM_1(a,0)
 #endif
Index: sys/net/pipex.h
===
RCS file: /cvs/src/sys/net/pipex.h,v
retrieving revision 1.22
diff -u -p -r1.22 pipex.h
--- sys/net/pipex.h 26 May 2020 07:06:37 -  1.22
+++ sys/net/pipex.h 5 Jun 2020 12:10:11 -
@@ -206,7 +206,6 @@ int   pipex_notify_close
 
 struct mbuf   *pipex_output (struct mbuf *, int, int, struct 
pipex_iface_context *);
 struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
-struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
 struct mbuf   *pipex_pppoe_input (struct mbuf *, struct pipex_session 
*);
 struct pipex_session  *pipex_pptp_lookup_session (struct mbuf *);
 struct mbuf   *pipex_pptp_input (struct mbuf *, struct pipex_session 
*);
Index: usr.sbin/bgpd/rde.h
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.233
diff -u -p -r1.233 rde.h
--- usr.sbin/bgpd/rde.h 24 Jan 2020 05:44:05 -  1.233
+++ usr.sbin/bgpd/rde.h 5 Jun 2020 12:14:50 -
@@ -557,7 +557,6 @@ re_rib(struct rib_entry *re)
 }
 
 voidpath_init(u_int32_t);
-voidpath_init(u_int32_t);
 voidpath_shutdown(void);
 voidpath_hash_stats(struct rde_hashstats *);
 int path_compare(struct rde_aspath *, struct rde_aspath *);
Index: usr.sbin/relayd/agentx.c
===
RCS file: /cvs/src/usr.sbin/relayd/agentx.c,v
retrieving revision 1.14
diff -u -p -r1.14 agentx.c
--- usr.sbin/relayd/agentx.c28 May 2017 10:39:15 -  1.14
+++ usr.sbin/relayd/agentx.c5 Jun 2020 12:12:06 -
@@ -654,7 +654,6 @@ snmp_agentx_unregister_pdu(struct snmp_o
 
if (snmp_agentx_raw(pdu, , sizeof(uhdr)) == -1 ||
snmp_agentx_oid(pdu, oid) == -1 ||
-   snmp_agentx_oid(pdu, oid) == -1 ||
(range_index && snmp_agentx_int(pdu, _bound) == -1)) {
snmp_agentx_pdu_free(pdu);
return (NULL);
Index: usr.sbin/snmpd/agentx.c
===
RCS file: /cvs/src/usr.sbin/snmpd/agentx.c,v
retrieving revision 1.13
diff -u -p -r1.13 agentx.c
--- usr.sbin/snmpd/agentx.c 17 Jun 2018 18:19:59 -  1.13
+++ usr.sbin/snmpd/agentx.c 5 Jun 2020 12:12:53 -
@@ -658,7 +658,6 @@ snmp_agentx_unregister_pdu(struct snmp_o
 
if (snmp_agentx_raw(pdu, , sizeof(uhdr)) == -1 ||
snmp_agentx_oid(pdu, oid) == -1 ||
-   snmp_agentx_oid(pdu, oid) == -1 ||
(range_index && snmp_agentx_int(pdu, _bound) == -1)) {
snmp_agentx_pdu_free(pdu);
return (NULL);



Re: [patch] azalia: Intel 300 Series HD Audio

2020-05-31 Thread Benjamin Baier
On Fri, 29 May 2020 11:25:44 +0200
Bruno Flueckiger  wrote:

> Hi,
> 
> My brand new laptop HP EliteBook 850 G6 comes with an Intel 300 Series
> HD Audio device rev 0x11. The device shows up as not configured in the
> dmesg. The PCI config space of the device identifies its subclass as
> PCI_SUBCLASS_MULTIMEDIA_AUDIO instead of PCI_SUBCLASS_MULTIMEDIA_HDAUDIO
> 
> The patch below makes the device work just fine on my laptop.
> 
> Cheers,
> Bruno
> 
> Index: sys/dev/pci/azalia.c
> ===
> RCS file: /cvs/src/sys/dev/pci/azalia.c,v
> retrieving revision 1.255
> diff -u -p -r1.255 azalia.c
> --- sys/dev/pci/azalia.c  18 Apr 2020 21:55:56 -  1.255
> +++ sys/dev/pci/azalia.c  28 May 2020 13:48:10 -
> @@ -481,7 +481,8 @@ azalia_pci_match(struct device *parent,
> 
>   pa = aux;
>   if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MULTIMEDIA
> - && PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MULTIMEDIA_HDAUDIO)
> + && (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MULTIMEDIA_HDAUDIO
> + || PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MULTIMEDIA_AUDIO))
>   return 1;
>   return 0;
>  }
> 

Hi.

Does your Laptop run with the latest BIOS? There was one released on May 11th.
https://support.hp.com/de-de/drivers/selfservice/swdetails/hp-elitebook-850-g6-notebook-pc/26609805/swItemId/ob-251060-1
The release notes state: Fixes an issue where the audio on the system stops 
functioning after the Intel Active Management Technology (AMT) option is 
disabled.

The azalia patch is in but I would prefer HP to fix their BIOS instead.

Greetings Ben



Re: userland clock_gettime proof of concept

2020-05-13 Thread Benjamin Baier
On Wed, 13 May 2020 16:09:57 +0200
Robert Nagy  wrote:
> On 13/05/20 17:03 +0300, Paul Irofti wrote:
> > Here is a stress test from robert@:
> > 
> > robert@x202:/home/robert> time ./t && time ./t2
> > 0m00.11s real 0m00.12s user 0m00.00s system
> > 0m09.99s real 0m02.64s user 0m03.36s system
> > t is clock_gettime() and t2 is SYS_clock_gettime()
> 
> I am in the middle of rebuilding the packages that should gain significant
> speedup right now. That small test does 5 million calls to clock_gettime,
> so it is a bit over-reaching but still it shows the difference.

Well, it's pretty close to a real world desktop system (4mio in 27sec)

root# time btrace calling_clock_gettime.bt  
^C@num[chrome]: 2476715
@num[java]: 1429533
@num[Xorg]: 308404
@num[sndiod]: 126398
@num[conky]: 116
@num[sh]: 106
@num[syslogd]: 2
0m27.12s real 0m04.64s user 0m01.89s system



pfkeyv2.c: Mem leak

2020-03-04 Thread Benjamin Baier
Hi,

pfkeyv2.c:1091:pfkeyv2_send(struct socket *so, void *message, int len)
leaks memory in the SADB_REGISTER case (line 1579).
It reuses void *freeme multiple times to build up void *headers[].

headers[] are bcopy'ed to another buffer inside of pfkeyv2_sendmessage()
(line 2064) so as the name implies *freeme is safe to be freed at the end.

Found by llvm/scan-build.
Also don't check for NULL before free(), could do a pass over the entire file.

Only compile tested.

- Ben 

Index: pfkeyv2.c
===
RCS file: /cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.198
diff -u -p -r1.198 pfkeyv2.c
--- pfkeyv2.c   17 Jul 2019 18:52:46 -  1.198
+++ pfkeyv2.c   3 Mar 2020 17:58:22 -
@@ -1098,7 +1098,8 @@ pfkeyv2_send(struct socket *so, void *me
struct radix_node_head *rnh;
struct radix_node *rn = NULL;
struct pkpcb *kp, *bkp;
-   void *freeme = NULL, *bckptr = NULL;
+   void *freeme = NULL, *freeme2 = NULL, *freeme3 = NULL;
+   void *bckptr = NULL;
void *headers[SADB_EXT_MAX + 1];
union sockaddr_union *sunionp;
struct tdb *sa1 = NULL, *sa2 = NULL;
@@ -1605,7 +1606,7 @@ pfkeyv2_send(struct socket *so, void *me
 
i = sizeof(struct sadb_supported) + sizeof(aalgs);
 
-   if (!(freeme = malloc(i, M_PFKEY, M_NOWAIT | M_ZERO))) {
+   if (!(freeme2 = malloc(i, M_PFKEY, M_NOWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
@@ -1616,34 +1617,34 @@ pfkeyv2_send(struct socket *so, void *me
(1 << ((struct sadb_msg *)message)->sadb_msg_satype);
keyunlock(kp, s);
 
-   ssup = (struct sadb_supported *) freeme;
+   ssup = (struct sadb_supported *) freeme2;
ssup->sadb_supported_len = i / sizeof(uint64_t);
 
{
-   void *p = freeme + sizeof(struct sadb_supported);
+   void *p = freeme2 + sizeof(struct sadb_supported);
 
bcopy([0], p, sizeof(aalgs));
}
 
-   headers[SADB_EXT_SUPPORTED_AUTH] = freeme;
+   headers[SADB_EXT_SUPPORTED_AUTH] = freeme2;
 
i = sizeof(struct sadb_supported) + sizeof(calgs);
 
-   if (!(freeme = malloc(i, M_PFKEY, M_NOWAIT | M_ZERO))) {
+   if (!(freeme3 = malloc(i, M_PFKEY, M_NOWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
 
-   ssup = (struct sadb_supported *) freeme;
+   ssup = (struct sadb_supported *) freeme3;
ssup->sadb_supported_len = i / sizeof(uint64_t);
 
{
-   void *p = freeme + sizeof(struct sadb_supported);
+   void *p = freeme3 + sizeof(struct sadb_supported);
 
bcopy([0], p, sizeof(calgs));
}
 
-   headers[SADB_X_EXT_SUPPORTED_COMP] = freeme;
+   headers[SADB_X_EXT_SUPPORTED_COMP] = freeme3;
 
break;
 
@@ -2064,14 +2065,14 @@ ret:
 
 realret:
 
-   if (freeme)
-   free(freeme, M_PFKEY, 0);
+   free(freeme, M_PFKEY, 0);
+   free(freeme2, M_PFKEY, 0);
+   free(freeme3, M_PFKEY, 0);
 
explicit_bzero(message, len);
free(message, M_PFKEY, 0);
 
-   if (sa1)
-   free(sa1, M_PFKEY, 0);
+   free(sa1, M_PFKEY, 0);
 
return (rval);
 }



pfioctl needs to ignore unknown af

2020-01-08 Thread Benjamin Baier
Hi.

pfioctl() needs to ignore unknown af supplied from userland (root only)
which can lead to kernel panic.

This fixes syzbot+92be143c2dd1746cf...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=18bd5fa9e22c139d0a4c34dd6c7c1f3fd6eec42a

-- Ben

Index: pf_ioctl.c
===
RCS file: /cvs/src/sys/net/pf_ioctl.c,v
retrieving revision 1.347
diff -u -p -r1.347 pf_ioctl.c
--- pf_ioctl.c  26 Nov 2019 19:57:52 -  1.347
+++ pf_ioctl.c  8 Jan 2020 17:33:26 -
@@ -1807,6 +1807,18 @@ pfioctl(dev_t dev, u_long cmd, caddr_t a
int  m = 0, direction = pnl->direction;
int  sidx, didx;
 
+   switch (pnl->af) {
+   case AF_INET:
+   break;
+#ifdef INET6
+   case AF_INET6:
+   break;
+#endif /* INET6 */
+   default:
+   error = EINVAL;
+   goto fail;
+   }
+
/* NATLOOK src and dst are reversed, so reverse sidx/didx */
sidx = (direction == PF_IN) ? 1 : 0;
didx = (direction == PF_IN) ? 0 : 1;



Re: vmctl(8): uninitialized value

2020-01-02 Thread Benjamin Baier
On Thu, 2 Jan 2020 18:56:14 +0100
Klemens Nanni  wrote:

> On Thu, Jan 02, 2020 at 04:37:17PM +0100, Benjamin Baier wrote:
> > "case CMD_SEND:" sets done=1 so ret will never be written to and
> > the uninitialized value of ret is used to determine the return
> > value of the function vmmaction.
> Good catch:
> 
>   $ doas vmctl start -b ~/vm/bsd.rd -m 128M test ; echo $?
>   vmctl: starting without disks
>   vmctl: starting without network interfaces
>   vmctl: started vm 4 successfully, tty /dev/ttyp2
>   0
>   $ doas vmctl send test >/dev/null ; echo $?
>   vmctl: sent vm test successfully
>   1
> 
> With your diff it exits zero.
> 
> I also just noticed that above example reproducibly causes vmd(8) to
> exit:
> 
> Jan  2 18:53:57 eru vmd[55128]: startup
> Jan  2 18:54:18 eru vmd[55128]: test: started vm 4 successfully, tty 
> /dev/ttyp2
> Jan  2 18:54:28 eru vmd[49983]: priv exiting, pid 49983
> Jan  2 18:54:28 eru vmd[29885]: control exiting, pid 29885

I don't get vmd to exit, but got this in /var/log/messages with the above 
example:
Jan  2 21:38:05 x220 vmd[86810]: control_dispatch_vmd: lost control connection: 
fd 7

root# vmd -dvvv 
startup
vm_register: registering vm 1
/etc/vm.conf:12: vm "amd64" registered (disabled)
/etc/vm.conf:16: switch "uplink" registered
vm_priv_brconfig: interface bridge0 description switch1-uplink
vmd_configure: setting staggered start configuration to parallelism: 4 and 
delay: 30
vmd_configure: starting vms in staggered fashion
start_vm_batch: starting batch of 4 vms
start_vm_batch: not starting vm amd64 (disabled)
start_vm_batch: done starting vms
config_getconfig: priv retrieving config
config_getconfig: control retrieving config
config_getconfig: vmm retrieving config
vm_register: registering vm 2
vm_opentty: vm test tty /dev/ttyp8 uid 0 gid 4 mode 620
vm_register: registering vm 2
test: started vm 2 successfully, tty /dev/ttyp8
loadfile_elf: loaded ELF kernel
run_vm: initializing hardware for vm test
pic_set_elcr: setting level triggered mode for irq 3
pic_set_elcr: setting level triggered mode for irq 5
run_vm: starting vcpu threads for vm test
vcpu_reset: resetting vcpu 0 for vm 8
run_vm: waiting on events for VM test
vcpu_exit_i8253: channel 0 reset, mode=2, start=65535
vcpu_process_com_lcr: set baudrate = 115200
i8259_write_datareg: master pic, reset IRQ vector to 0x20
i8259_write_datareg: slave pic, reset IRQ vector to 0x28
vcpu_exit_i8253: channel 0 reset, mode=2, start=11932
vcpu_process_com_lcr: set baudrate = 115200
vcpu_process_com_lcr: set baudrate = 115200
vmd_dispatch_vmm: running vm: 2, vm_state: 0x1
vmd_dispatch_vmm: vm: 1, vm_state: 0x2
vmd_dispatch_control: sending fd to vmm
i8253_dump: sending PIT
i8259_dump: sending PIC
i8259_dump: sending ELCR
ns8250_dump: sending UART
mc146818_dump: sending RTC
fw_cfg_dump: sending fw_cfg state
pci_dump: sending pci
viornd_dump: sending viornd
vioblk_dump: sending vioblk
vionet_dump: sending vionet
vmmci_dump: sending vmmci
vm_remove: vmm vmm_dispatch_vm removing vm 2 from running config
vm_stop: vmm vmm_dispatch_vm stopping vm 2
test: sent vm 2 successfully.
vm_remove: parent vmd_dispatch_vmm removing vm 2 from running config
vm_stop: parent vmd_dispatch_vmm stopping vm 2
control_dispatch_vmd: lost control connection: fd 7
vmm_sighdlr: handling signal 20


> OK kn if anyone wants to commit, otherwise I'll do so tomorrow when
> looking into this issue.
> 



vmctl(8): uninitialized value

2020-01-02 Thread Benjamin Baier
Hi.

"case CMD_SEND:" sets done=1 so ret will never be written to and
the uninitialized value of ret is used to determine the return
value of the function vmmaction.

-- Ben


Index: main.c
===
RCS file: /cvs/src/usr.sbin/vmctl/main.c,v
retrieving revision 1.61
diff -u -p -r1.61 main.c
--- main.c  28 Dec 2019 18:36:01 -  1.61
+++ main.c  2 Jan 2020 15:09:28 -
@@ -265,6 +265,7 @@ vmmaction(struct parse_result *res)
case CMD_SEND:
send_vm(res->id, res->name);
done = 1;
+   ret = 0;
break;
case CMD_RECEIVE:
vm_receive(res->id, res->name);



kill VNDIOCGET60

2019-11-18 Thread Benjamin Baier
Hi, found this.

 -- Ben

Index: vndioctl.h
===
RCS file: /cvs/src/sys/dev/vndioctl.h,v
retrieving revision 1.10
diff -u -p -r1.10 vndioctl.h
--- vndioctl.h  14 Dec 2016 18:59:12 -  1.10
+++ vndioctl.h  18 Nov 2019 20:11:50 -
@@ -75,8 +75,6 @@ struct vnd_user {
  */
 #define VNDIOCSET  _IOWR('F', 0, struct vnd_ioctl) /* enable disk */
 #define VNDIOCCLR  _IOW('F', 1, struct vnd_ioctl)  /* disable disk */
-/* XXX kill after 6.1 */
-/* #define VNDIOCGET60 _IOWR('F', 2, struct vnd_user60) */
 #define VNDIOCGET  _IOWR('F', 3, struct vnd_user)  /* get disk info */
 
 #endif /* !_SYS_VNDIOCTL_H_ */



Comment fix: No mcontext

2019-07-12 Thread Benjamin Baier
Hi,

there is no mcontext, and since V1.2 of process_machdep.c struct reg
and struct trapframe don't have to be closely synced.
process_machdep.c no longer memcpy's one to the other.

Greetings Ben

Thu Jul 11 23:45:14 CEST 2019
/home/cvsgit/hellfish/src/sys/arch/amd64/include
Index: reg.h
===
RCS file: /cvs/src/sys/arch/amd64/include/reg.h,v
retrieving revision 1.6
diff -u -p -r1.6 reg.h
--- reg.h   23 Mar 2011 16:54:34 -  1.6
+++ reg.h   11 Jul 2019 21:45:11 -
@@ -75,8 +75,6 @@
 
 /*
  * Registers accessible to ptrace(2) syscall for debugger use.
- * Same as mcontext.__gregs and struct trapframe, they must
- * remain synced (XXX should use common structure).
  */
 struct reg {
int64_t r_rdi;



Re: [WIP] new sysctl hw.gpuperf

2019-06-28 Thread Benjamin Baier
On Mon, 24 Jun 2019 13:02:52 +0200
Benjamin Baier  wrote:

> Hi,
> 
> this is wip for a new sysctl that implements gpu throttling.
> Only implemented for inteldrm right now, and tested on a single amd64
> laptop. Helps to keep the GPU/CPU cooler and save some energy.
> 
> Most of the diff is for sensors to verify if the sysctl works, and will
> be removed once i'm confident enought.
> 
> Some notes from my x220 with integrated intel graphics (HD3000):
> - min gpu freq: 650 MHz
> - max gpu freq: 1300 MHz
> Setting hw.gpuperf to anything > 10 (max. 700 MHz) will eventually run
> into thermal throttling (GPU temp 96 deg C).
> Setting hw.gpuperf=0 (650MHz) will run Youtube video and browser games
> together fine, and reduce GPU/CPU temp from 96 deg C to about 80 - 86 deg C.
> 
> thoughts? tests?
> 
> Greetings Ben

Thanks, for the feedback.

Updated diff below. Seems to work without regressions so far on at least
HD3000 (Sandy Bridge), HD4400 (Haswell), HD510 (Skylake), HD405 (Atom x7).
My findings of reduced temps where also replicated.

===

This implements a new sysctl hw.gpuperf.
This will throttle down your graphic card for 
better thermal and energy management.
Unlike hw.setperf which sets a fixed CPU clock,
hw.gpuperf will limit the max. clock the GPU is
allowed to reach. So it will still downclock while
idle even at hw.gpuperf=100.

Patch Version 2
Patch apply directions have changed
Includes man page change
Header cleanup
Patch Version 1
Throttle down to base freq on haswell & broadwell
Remove sensors, use debug printf
Need:
OpenBSD-current source code
Only implemented for intel graphic (atm.)
To apply:
cd /usr/src && patch < gpuperf.diff
Rebuild and install a new kernel:
KK=`sysctl -n kern.osversion | cut -d# -f1`
cd /usr/src/sys/arch/`machine`/compile/$KK
make obj
make config
make
make install
Rebuild and install a new sysctl:
cp /usr/src/sys/sys/sysctl.h /usr/include/sys/
cd /usr/src/sbin/sysctl
make obj
make
make install
Test various sysctl hw.gpuperf settings (0, 10, ..., 100)
Send output of: dmesg | grep -e gpuperf -e inteldrm -e cpu0
and test results/feedback to program...@netzbasis.de

Wed Jun 26 12:16:25 CEST 2019
/home/cvsgit/hellfish/src
Index: lib/libc/sys/sysctl.2
===
RCS file: /cvs/src/lib/libc/sys/sysctl.2,v
retrieving revision 1.27
diff -u -p -r1.27 sysctl.2
--- lib/libc/sys/sysctl.2   9 May 2019 15:05:47 -   1.27
+++ lib/libc/sys/sysctl.2   26 Jun 2019 10:09:56 -
@@ -282,6 +282,7 @@ privileges may change the value.
 .It Dv HW_DISKCOUNT Ta "integer" Ta "no"
 .It Dv HW_DISKNAMES Ta "string" Ta "no"
 .It Dv HW_DISKSTATS Ta "struct" Ta "no"
+.It Dv HW_GPUPERF Ta "integer" Ta "yes"
 .It Dv HW_MACHINE Ta "string" Ta "no"
 .It Dv HW_MODEL Ta "string" Ta "no"
 .It Dv HW_NCPU Ta "integer" Ta "no"
@@ -324,6 +325,10 @@ A comma-separated list of disk names.
 An array of
 .Vt struct diskstats
 structures containing disk statistics.
+.It Dv HW_GPUPERF Pq Va hw.gpuperf
+Maximum GPU performance
+.Pq percentage .
+Only for supported hardware.
 .It Dv HW_MACHINE Pq Va hw.machine
 The machine class.
 .It Dv HW_MODEL Pq Va hw.model
Index: sys/conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.671
diff -u -p -r1.671 files
--- sys/conf/files  4 May 2019 11:34:47 -   1.671
+++ sys/conf/files  25 Jun 2019 20:21:29 -
@@ -710,6 +710,7 @@ file kern/subr_autoconf.c
 file kern/subr_disk.c
 file kern/subr_evcount.c
 file kern/subr_extent.c
+file kern/subr_gpuperf.c   inteldrm
 file kern/subr_hibernate.c hibernate
 file kern/subr_kubsan.ckubsan
 file kern/subr_log.c
Index: sys/dev/pci/drm/i915/i915_drv.c
===
RCS file: /cvs/src/sys/dev/pci/drm/i915/i915_drv.c,v
retrieving revision 1.118
diff -u -p -r1.118 i915_drv.c
--- sys/dev/pci/drm/i915/i915_drv.c 8 May 2019 15:55:56 -   1.118
+++ sys/dev/pci/drm/i915/i915_drv.c 25 Jun 2019 20:21:29 -
@@ -46,6 +46,10 @@
 #include 
 #include 
 
+#ifdef __OpenBSD__
+#include 
+#endif /* __OpenBSD__ */
+
 #include "i915_drv.h"
 #include "i915_trace.h"
 #include "i915_pmu.h"
@@ -3668,12 +3672,54 @@ inteldrm_attachhook(struct device *self)
 
config_found_sm(self, , wsemuldisplaydevprint,
wsemuldisplaydevsubmatch);
+
+#ifdef __OpenBSD__
+   gpuperf_register(dev_priv->sc_dev.dv_xname,
+   inteldrm_set_gpuperf, dev_priv);
+#endif /* __OpenBSD__ */
+
return;
 
 fail:
inteldrm_fatal_error = 1;
 

[WIP] new sysctl hw.gpuperf

2019-06-24 Thread Benjamin Baier
tel_gpu_freq(dev_priv, rps->cur_freq);
+   dev_priv->sc_sensor[0].value = freq0 * 1000 * 1000 * 1000 * 1000;
+
+   freq0 = dev_priv->mem_freq;
+   dev_priv->sc_sensor[1].value = freq0 * 1000 * 1000 * 1000 * 1000;
+
+   freq0 = rps->min_freq_softlimit;
+   dev_priv->sc_sensor[4].value = freq0 * 50;
+
+   freq0 = rps->max_freq_softlimit;
+   dev_priv->sc_sensor[5].value = freq0 * 50;
 }
 
 int
Index: dev/pci/drm/i915/i915_drv.h
===
RCS file: /cvs/src/sys/dev/pci/drm/i915/i915_drv.h,v
retrieving revision 1.82
diff -u -p -r1.82 i915_drv.h
--- dev/pci/drm/i915/i915_drv.h 4 May 2019 11:34:47 -   1.82
+++ dev/pci/drm/i915/i915_drv.h 23 Jun 2019 21:38:47 -
@@ -2274,6 +2274,9 @@ struct inteldrm_softc {
 
struct i915_pmu pmu;
 
+   struct ksensor sc_sensor[6];
+   struct ksensordev sc_sensordev;
+
/*
 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
 * will be rejected. Instead look for a better place.
@@ -4014,3 +4017,6 @@ static inline int intel_hws_csb_write_in
 }
 
 #endif
+
+void inteldrm_set_gpuperf(int level, void *arg);
+void inteldrm_refresh_sensor(void *);
Index: dev/pci/drm/i915/intel_pm.c
===
RCS file: /cvs/src/sys/dev/pci/drm/i915/intel_pm.c,v
retrieving revision 1.43
diff -u -p -r1.43 intel_pm.c
--- dev/pci/drm/i915/intel_pm.c 14 Apr 2019 10:14:52 -  1.43
+++ dev/pci/drm/i915/intel_pm.c 23 Jun 2019 20:02:34 -
@@ -6316,6 +6316,8 @@ static void rps_set_power(struct drm_i91
if (new_power == rps->power.mode)
return;
 
+   dev_priv->sc_sensor[3].value = new_power;
+
/* Note the units here are not exactly 1us, but 1280ns. */
switch (new_power) {
case LOW_POWER:
@@ -7200,12 +7202,18 @@ static void gen6_update_ring_freq(struct
 * No floor required for ring frequency on SKL.
 */
ring_freq = gpu_freq;
+   dev_priv->sc_sensor[2].value = ring_freq * 100\
+   * 1000 * 1000 * 1000 * 1000;
} else if (INTEL_GEN(dev_priv) >= 8) {
/* max(2 * GT, DDR). NB: GT is 50MHz units */
ring_freq = max(min_ring_freq, gpu_freq);
+   dev_priv->sc_sensor[2].value = ring_freq * 50\
+   * 1000 * 1000 * 1000 * 1000;
} else if (IS_HASWELL(dev_priv)) {
ring_freq = mult_frac(gpu_freq, 5, 4);
ring_freq = max(min_ring_freq, ring_freq);
+   dev_priv->sc_sensor[2].value = ring_freq * 50\
+   * 1000 * 1000 * 1000 * 1000;
/* leave ia_freq as the default, chosen by cpufreq */
} else {
/* On older processors, there is no separate ring
@@ -7220,6 +7228,7 @@ static void gen6_update_ring_freq(struct
else
ia_freq = max_ia_freq - ((diff * 
scaling_factor) / 2);
ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100);
+   dev_priv->sc_sensor[2].value = 0;
}
 
sandybridge_pcode_write(dev_priv,
Index: kern/kern_sysctl.c
===
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.360
diff -u -p -r1.360 kern_sysctl.c
--- kern/kern_sysctl.c  16 Jun 2019 00:56:53 -  1.360
+++ kern/kern_sysctl.c  24 Jun 2019 09:48:19 -
@@ -103,6 +103,9 @@
 #include 
 #endif
 
+#ifndef SMALL_KERNEL
+#include 
+#endif /* !SMALL_KERNEL */
 #ifdef SYSVMSG
 #include 
 #endif
@@ -749,6 +752,8 @@ hw_sysctl(int *name, u_int namelen, void
return (sysctl_hwsetperf(oldp, oldlenp, newp, newlen));
case HW_PERFPOLICY:
return (sysctl_hwperfpolicy(oldp, oldlenp, newp, newlen));
+   case HW_GPUPERF:
+   return (sysctl_hwgpuperf(oldp, oldlenp, newp, newlen));
 #endif /* !SMALL_KERNEL */
case HW_VENDOR:
if (hw_vendor)
Index: kern/subr_gpuperf.c
===
RCS file: kern/subr_gpuperf.c
diff -N kern/subr_gpuperf.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ kern/subr_gpuperf.c 24 Jun 2019 10:04:35 -
@@ -0,0 +1,86 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2019 Benjamin Baier 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING AL

Re: cmdfile for config -ef

2019-05-11 Thread Benjamin Baier
On Sat, 11 May 2019 13:26:14 -0600
"Theo de Raadt"  wrote:

> Ted Unangst  wrote:
> 
> > Benjamin Baier wrote:
> > > On Sat, 11 May 2019 11:18:02 -0400
> > > "Ted Unangst"  wrote:
> > > 
> > > > This adds a new option to config, -c cmdfile, that allows reading 
> > > > commands
> > > > from a file instead of stdin. This makes it easier to script.
> > > 
> > > Interesting. Can the cmdfile be /bsd ?
> > > So something like config -u but without the need of /dev/mem ?
> > 
> > No, the intended use case is not to copy options between kernels, but to 
> > apply
> > a consistent set of changes after linking.
> 
> @ boot-time, /etc/rc kernel relink script
>   KARL links a new kernel
>   apply config -e changes
>   install
>   hash it

I do realize that it's a polished version of what I wrote yesterday.
https://marc.info/?l=openbsd-misc=155751021025538=2
It just made me think that it may be possible without yet another config file.

Just thinking out loud, do carry on...



Re: cmdfile for config -ef

2019-05-11 Thread Benjamin Baier
On Sat, 11 May 2019 11:18:02 -0400
"Ted Unangst"  wrote:

> This adds a new option to config, -c cmdfile, that allows reading commands
> from a file instead of stdin. This makes it easier to script.

Interesting. Can the cmdfile be /bsd ?
So something like config -u but without the need of /dev/mem ?


> Index: config.8
> ===
> RCS file: /home/cvs/src/usr.sbin/config/config.8,v
> retrieving revision 1.66
> diff -u -p -r1.66 config.8
> --- config.8  25 Apr 2018 12:01:11 -  1.66
> +++ config.8  11 May 2019 15:16:45 -
> @@ -43,6 +43,7 @@
>  .Op Fl s Ar srcdir
>  .Op Ar config-file
>  .Nm config
> +.Op Fl c Ar cmdfile
>  .Op Fl u
>  .Op Fl f | o Ar outfile
>  .Fl e
> @@ -103,6 +104,9 @@ directories above the build directory).
>  .Pp
>  For kernel modification, the options are as follows:
>  .Bl -tag -width Ds
> +.It Fl c Ar cmdfile
> +Read commands from the specified file instead of the standard input.
> +Save and quit automatically when the end of file is reached.
>  .It Fl e
>  Allows the modification of kernel device configuration (see
>  .Xr boot_config 8 ) .
> Index: main.c
> ===
> RCS file: /home/cvs/src/usr.sbin/config/main.c,v
> retrieving revision 1.59
> diff -u -p -r1.59 main.c
> --- main.c22 Jun 2017 15:57:16 -  1.59
> +++ main.c11 May 2019 15:00:34 -
> @@ -82,7 +82,7 @@ usage(void)
>  
>   fprintf(stderr,
>   "usage: %s [-p] [-b builddir] [-s srcdir] [config-file]\n"
> - "   %s [-u] [-f | -o outfile] -e infile\n",
> + "   %s [-c cmdfile] [-u] [-f | -o outfile] -e infile\n",
>   __progname, __progname);
>  
>   exit(1);
> @@ -92,6 +92,7 @@ int pflag = 0;
>  char *sflag = NULL;
>  char *bflag = NULL;
>  char *startdir;
> +char *cmdfile;
>  
>  int
>  main(int argc, char *argv[])
> @@ -105,9 +106,11 @@ main(int argc, char *argv[])
>   err(1, "pledge");
>  
>   pflag = eflag = uflag = fflag = 0;
> - while ((ch = getopt(argc, argv, "epfb:s:o:u")) != -1) {
> + while ((ch = getopt(argc, argv, "c:epfb:s:o:u")) != -1) {
>   switch (ch) {
> -
> + case 'c':
> + cmdfile = optarg;
> + break;
>   case 'o':
>   outfile = optarg;
>   break;
> Index: misc.c
> ===
> RCS file: /home/cvs/src/usr.sbin/config/misc.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 misc.c
> --- misc.c2 Oct 2011 22:20:49 -   1.9
> +++ misc.c11 May 2019 15:08:56 -
> @@ -38,13 +38,10 @@
>  extern int verbose;
>  
>  int
> -ask_cmd(cmd_t *cmd)
> +parse_cmd(cmd_t *cmd, char *lbuf)
>  {
> - char lbuf[100], *cp, *buf;
> + char *cp, *buf;
>  
> - /* Get input */
> - if (fgets(lbuf, sizeof lbuf, stdin) == NULL)
> - errx(1, "eof");
>   lbuf[strcspn(lbuf, "\n")] = '\0';
>   if (verbose)
>   printf("%s\n", lbuf);
> @@ -59,6 +56,17 @@ ask_cmd(cmd_t *cmd)
>   strlcpy(cmd->args, buf, sizeof cmd->args);
>  
>   return (0);
> +}
> +
> +int
> +ask_cmd(cmd_t *cmd)
> +{
> + char lbuf[100];
> +
> + /* Get input */
> + if (fgets(lbuf, sizeof lbuf, stdin) == NULL)
> + errx(1, "eof");
> + return parse_cmd(cmd, lbuf);
>  }
>  
>  int
> Index: misc.h
> ===
> RCS file: /home/cvs/src/usr.sbin/config/misc.h,v
> retrieving revision 1.4
> diff -u -p -r1.4 misc.h
> --- misc.h3 Jun 2003 00:52:35 -   1.4
> +++ misc.h11 May 2019 15:10:04 -
> @@ -33,6 +33,7 @@
>  
>  /* Prototypes */
>  int ask_cmd(cmd_t *);
> +int parse_cmd(cmd_t *, char *);
>  int ask_yn(const char *);
>  
>  #endif /* _MISC_H */
> Index: ukcutil.c
> ===
> RCS file: /home/cvs/src/usr.sbin/config/ukcutil.c,v
> retrieving revision 1.23
> diff -u -p -r1.23 ukcutil.c
> --- ukcutil.c 27 Sep 2017 15:14:52 -  1.23
> +++ ukcutil.c 11 May 2019 15:14:25 -
> @@ -29,6 +29,7 @@
>  #include 
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -1295,13 +1296,61 @@ add_history(int devno, short unit, short
>  }
>  
>  int
> +config_fromfile(const char *cmdfile) {
> + FILE *fp;
> + cmd_t cmd;
> + int i;
> +
> + fp = fopen(cmdfile, "r");
> + if (fp == NULL)
> + err(1, "open %s", cmdfile);
> +
> + /* Set up command table pointer */
> + cmd.table = cmd_table;
> +
> + /* Edit cycle */
> + do {
> + char lbuf[100];
> +
> + /* Get input */
> + if (fgets(lbuf, sizeof lbuf, fp) == NULL)
> + break;
> + parse_cmd(, lbuf);
> +
> + if (cmd.cmd[0] == '\0')
> + continue;
> + for 

Re: nm(1): return on malloc error

2019-03-02 Thread Benjamin Baier
Ping.

On malloc error symtab is unmapped, so proceeding on will lead to a NULL pointer
dereference.

On Wed, 20 Feb 2019 17:55:08 +0100
Benjamin Baier  wrote:

> Hi.
> 
> When malloc fails we should return like the MMAP case does.
> 
> Greetings Ben
> 
Index: nm.c
===
RCS file: /cvs/src/usr.bin/nm/nm.c,v
retrieving revision 1.53
diff -u -p -u -C10 -r1.53 nm.c
*** nm.c27 Oct 2017 16:47:08 -  1.53
--- nm.c20 Feb 2019 17:34:01 -
*** show_symtab(off_t off, u_long len, const
*** 374,393 
--- 374,394 
restore = ftello(fp);

MMAP(symtab, len, PROT_READ, MAP_PRIVATE|MAP_FILE, fileno(fp), off);
if (symtab == MAP_FAILED)
return (1);

namelen = sizeof(ar_head.ar_name);
if ((p = malloc(sizeof(ar_head.ar_name))) == NULL) {
warn("%s: malloc", name);
MUNMAP(symtab, len);
+   return (1);
}

printf("\nArchive index:\n");
num = betoh32(*symtab);
strtab = (char *)(symtab + num + 1);
for (ps = symtab + 1; num--; ps++, strtab += strlen(strtab) + 1) {
if (fseeko(fp, betoh32(*ps), SEEK_SET)) {
warn("%s: fseeko", name);
rval = 1;
break;



nm(1): return on malloc error

2019-02-20 Thread Benjamin Baier
Hi.

When malloc fails we should return like the MMAP case does.

Greetings Ben

Index: nm.c
===
RCS file: /cvs/src/usr.bin/nm/nm.c,v
retrieving revision 1.53
diff -u -p -u -C10 -r1.53 nm.c
*** nm.c27 Oct 2017 16:47:08 -  1.53
--- nm.c20 Feb 2019 17:34:01 -
*** show_symtab(off_t off, u_long len, const
*** 374,393 
--- 374,394 
restore = ftello(fp);

MMAP(symtab, len, PROT_READ, MAP_PRIVATE|MAP_FILE, fileno(fp), off);
if (symtab == MAP_FAILED)
return (1);

namelen = sizeof(ar_head.ar_name);
if ((p = malloc(sizeof(ar_head.ar_name))) == NULL) {
warn("%s: malloc", name);
MUNMAP(symtab, len);
+   return (1);
}

printf("\nArchive index:\n");
num = betoh32(*symtab);
strtab = (char *)(symtab + num + 1);
for (ps = symtab + 1; num--; ps++, strtab += strlen(strtab) + 1) {
if (fseeko(fp, betoh32(*ps), SEEK_SET)) {
warn("%s: fseeko", name);
rval = 1;
break;



Re: athn(4) hostap: mem leak

2018-12-05 Thread Benjamin Baier
Finally got a usb athn device. I can confirm that this codepath is hit
in hostap mode and the device still works with the patch.

athn0 at uhub4 port 2 configuration 1 interface 0 "ATHEROS USB2.0 WLAN" rev 
2.00/1.08 addr 3
athn0: AR9271 rev 1 (1T1R), ROM rev 13, address c4:e9:84:dc:27:11

Full dmesg below.

On Sun, 2 Dec 2018 10:15:44 +0100
Benjamin Baier  wrote:

> On Sat, 1 Dec 2018 15:48:13 -0200
> Martin Pieuchot  wrote:
> 
> > On 30/11/18(Fri) 13:49, Benjamin Baier wrote:  
> > > Hi
> > > 
> > > There is a leak of *arg in 
> > > dev/usb/if_athn_usb.c:athn_usb_newauth() line 1263
> > > since Rev. 1.49
> > > Because athn_usb_do_async() memcpy's the argument anyway.
> > > 
> > > Found with llvm/scan-build.
> > > 
> > > Instead of adding free(arg) I opted to make this function
> > > more like the other ones which call athn_usb_do_async.
> > > 
> > > Only compile tested... looking for tests.
> > 
> > You should also remove the free(arg...) in athn_usb_newauth_cb().  
> Indeed, new patch attached.


Index: if_athn_usb.c
===
RCS file: /cvs/src/sys/dev/usb/if_athn_usb.c,v
retrieving revision 1.51
diff -u -p -r1.51 if_athn_usb.c
--- if_athn_usb.c   6 Sep 2018 11:50:54 -   1.51
+++ if_athn_usb.c   2 Dec 2018 09:09:29 -
@@ -1202,8 +1202,6 @@ athn_usb_newauth_cb(struct athn_usb_soft
struct athn_node *an = (struct athn_node *)ni;
int s, error = 0;
 
-   free(arg, M_DEVBUF, sizeof(*arg));
-
if (ic->ic_state != IEEE80211_S_RUN)
return;
 
@@ -1231,7 +1229,7 @@ athn_usb_newauth(struct ieee80211com *ic
struct ifnet *ifp = >ic_if;
struct athn_node *an = (struct athn_node *)ni;
int nsta;
-   struct athn_usb_newauth_cb_arg *arg;
+   struct athn_usb_newauth_cb_arg arg;
 
if (ic->ic_opmode != IEEE80211_M_HOSTAP)
return 0;
@@ -1254,12 +1252,9 @@ athn_usb_newauth(struct ieee80211com *ic
 * In a process context, try to add this node to the
 * firmware table and confirm the AUTH request.
 */
-   arg = malloc(sizeof(*arg), M_DEVBUF, M_NOWAIT);
-   if (arg == NULL)
-   return ENOMEM;
-   arg->ni = ieee80211_ref_node(ni);
-   arg->seq = seq;
-   athn_usb_do_async(usc, athn_usb_newauth_cb, arg, sizeof(*arg));
+   arg.ni = ieee80211_ref_node(ni);
+   arg.seq = seq;
+   athn_usb_do_async(usc, athn_usb_newauth_cb, , sizeof(arg));
return EBUSY;
 #else
return 0;



OpenBSD 6.4-current (GENERIC.MP) #492: Mon Dec  3 21:37:10 MST 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8451125248 (8059MB)
avail mem = 8185712640 (7806MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.6 @ 0xdae9c000 (64 entries)
bios0: vendor LENOVO version "8DET69WW (1.39 )" date 07/18/2013
bios0: LENOVO 4287CTO
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SLIC SSDT SSDT SSDT HPET APIC MCFG ECDT ASF! TCPA SSDT 
SSDT DMAR UEFI UEFI UEFI
acpi0: wakeup devices LID_(S3) SLPB(S3) IGBE(S4) EXP4(S4) EXP7(S4) EHC1(S3) 
EHC2(S3) HDEF(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2492.26 MHz, 06-2a-07
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.91 MHz, 06-2a-07
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.91 MHz, 06-2a-07
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VM

Re: athn(4) hostap: mem leak

2018-12-02 Thread Benjamin Baier
On Sat, 1 Dec 2018 15:48:13 -0200
Martin Pieuchot  wrote:

> On 30/11/18(Fri) 13:49, Benjamin Baier wrote:
> > Hi
> > 
> > There is a leak of *arg in 
> > dev/usb/if_athn_usb.c:athn_usb_newauth() line 1263
> > since Rev. 1.49
> > Because athn_usb_do_async() memcpy's the argument anyway.
> > 
> > Found with llvm/scan-build.
> > 
> > Instead of adding free(arg) I opted to make this function
> > more like the other ones which call athn_usb_do_async.
> > 
> > Only compile tested... looking for tests.  
> 
> You should also remove the free(arg...) in athn_usb_newauth_cb().
Indeed, new patch attached.

Index: if_athn_usb.c
===
RCS file: /cvs/src/sys/dev/usb/if_athn_usb.c,v
retrieving revision 1.51
diff -u -p -r1.51 if_athn_usb.c
--- if_athn_usb.c   6 Sep 2018 11:50:54 -   1.51
+++ if_athn_usb.c   2 Dec 2018 09:09:29 -
@@ -1202,8 +1202,6 @@ athn_usb_newauth_cb(struct athn_usb_soft
struct athn_node *an = (struct athn_node *)ni;
int s, error = 0;
 
-   free(arg, M_DEVBUF, sizeof(*arg));
-
if (ic->ic_state != IEEE80211_S_RUN)
return;
 
@@ -1231,7 +1229,7 @@ athn_usb_newauth(struct ieee80211com *ic
struct ifnet *ifp = >ic_if;
struct athn_node *an = (struct athn_node *)ni;
int nsta;
-   struct athn_usb_newauth_cb_arg *arg;
+   struct athn_usb_newauth_cb_arg arg;
 
if (ic->ic_opmode != IEEE80211_M_HOSTAP)
return 0;
@@ -1254,12 +1252,9 @@ athn_usb_newauth(struct ieee80211com *ic
 * In a process context, try to add this node to the
 * firmware table and confirm the AUTH request.
 */
-   arg = malloc(sizeof(*arg), M_DEVBUF, M_NOWAIT);
-   if (arg == NULL)
-   return ENOMEM;
-   arg->ni = ieee80211_ref_node(ni);
-   arg->seq = seq;
-   athn_usb_do_async(usc, athn_usb_newauth_cb, arg, sizeof(*arg));
+   arg.ni = ieee80211_ref_node(ni);
+   arg.seq = seq;
+   athn_usb_do_async(usc, athn_usb_newauth_cb, , sizeof(arg));
return EBUSY;
 #else
return 0;



Re: athn(4) hostap: mem leak

2018-12-01 Thread Benjamin Baier
On Fri, 30 Nov 2018 16:55:42 +0100
Alexandre Ratchov  wrote:

> On Fri, Nov 30, 2018 at 01:49:56PM +0100, Benjamin Baier wrote:
> > Hi
> > 
> > There is a leak of *arg in 
> > dev/usb/if_athn_usb.c:athn_usb_newauth() line 1263
> > since Rev. 1.49
> > Because athn_usb_do_async() memcpy's the argument anyway.
> > 
> > Found with llvm/scan-build.
> > 
> > Instead of adding free(arg) I opted to make this function
> > more like the other ones which call athn_usb_do_async.
> >   
> 
> Hi,
> 
> AFAICS, athn_usb_do_async() will schedule a call to
> athn_usb_newauth_cb(), which will use arg after the functin has
> returned. The arg memory location must stay valid after return from
> athn_usb_newauth(). So we can neither use free() nor a local variable.

athn_usb_do_async() takes care of that by memcpy-ing arg to cmd->data
before calling usb_add_task().

other calls to athn_usb_do_async() do use local variables.
if_athn_usb.c:1032:athn_usb_do_async(usc, athn_usb_newstate_cb, , 
sizeof(cmd));
if_athn_usb.c:1317:athn_usb_do_async(usc, athn_usb_ampdu_tx_start_cb, , 
sizeof(cmd));
if_athn_usb.c:1641:athn_usb_do_async(usc, athn_usb_set_key_cb, , 
sizeof(cmd));
if_athn_usb.c:1673:athn_usb_do_async(usc, athn_usb_delete_key_cb, , 
sizeof(cmd));

> The athn_usb_newauth_cb() callback calls free(), so there's no memory
> leak unless the callback is cancelled. I don't know it can be
> cancelled, I see no code doing so.
> 
> > Only compile tested... looking for tests.
> > 
> > Greetings Ben
> > 
> > Index: if_athn_usb.c
> > ===
> > RCS file: /cvs/src/sys/dev/usb/if_athn_usb.c,v
> > retrieving revision 1.51
> > diff -u -p -r1.51 if_athn_usb.c
> > --- if_athn_usb.c   6 Sep 2018 11:50:54 -   1.51
> > +++ if_athn_usb.c   29 Nov 2018 18:33:40 -
> > @@ -1231,7 +1231,7 @@ athn_usb_newauth(struct ieee80211com *ic
> > struct ifnet *ifp = >ic_if;
> > struct athn_node *an = (struct athn_node *)ni;
> > int nsta;
> > -   struct athn_usb_newauth_cb_arg *arg;
> > +   struct athn_usb_newauth_cb_arg arg;
> >  
> > if (ic->ic_opmode != IEEE80211_M_HOSTAP)
> > return 0;
> > @@ -1254,12 +1254,9 @@ athn_usb_newauth(struct ieee80211com *ic
> >  * In a process context, try to add this node to the
> >  * firmware table and confirm the AUTH request.
> >  */
> > -   arg = malloc(sizeof(*arg), M_DEVBUF, M_NOWAIT);
> > -   if (arg == NULL)
> > -   return ENOMEM;
> > -   arg->ni = ieee80211_ref_node(ni);
> > -   arg->seq = seq;
> > -   athn_usb_do_async(usc, athn_usb_newauth_cb, arg, sizeof(*arg));
> > +   arg.ni = ieee80211_ref_node(ni);
> > +   arg.seq = seq;
> > +   athn_usb_do_async(usc, athn_usb_newauth_cb, , sizeof(arg));
> > return EBUSY;
> >  #else
> > return 0;
> >   
> 



athn(4) hostap: mem leak

2018-11-30 Thread Benjamin Baier
Hi

There is a leak of *arg in 
dev/usb/if_athn_usb.c:athn_usb_newauth() line 1263
since Rev. 1.49
Because athn_usb_do_async() memcpy's the argument anyway.

Found with llvm/scan-build.

Instead of adding free(arg) I opted to make this function
more like the other ones which call athn_usb_do_async.

Only compile tested... looking for tests.

Greetings Ben

Index: if_athn_usb.c
===
RCS file: /cvs/src/sys/dev/usb/if_athn_usb.c,v
retrieving revision 1.51
diff -u -p -r1.51 if_athn_usb.c
--- if_athn_usb.c   6 Sep 2018 11:50:54 -   1.51
+++ if_athn_usb.c   29 Nov 2018 18:33:40 -
@@ -1231,7 +1231,7 @@ athn_usb_newauth(struct ieee80211com *ic
struct ifnet *ifp = >ic_if;
struct athn_node *an = (struct athn_node *)ni;
int nsta;
-   struct athn_usb_newauth_cb_arg *arg;
+   struct athn_usb_newauth_cb_arg arg;
 
if (ic->ic_opmode != IEEE80211_M_HOSTAP)
return 0;
@@ -1254,12 +1254,9 @@ athn_usb_newauth(struct ieee80211com *ic
 * In a process context, try to add this node to the
 * firmware table and confirm the AUTH request.
 */
-   arg = malloc(sizeof(*arg), M_DEVBUF, M_NOWAIT);
-   if (arg == NULL)
-   return ENOMEM;
-   arg->ni = ieee80211_ref_node(ni);
-   arg->seq = seq;
-   athn_usb_do_async(usc, athn_usb_newauth_cb, arg, sizeof(*arg));
+   arg.ni = ieee80211_ref_node(ni);
+   arg.seq = seq;
+   athn_usb_do_async(usc, athn_usb_newauth_cb, , sizeof(arg));
return EBUSY;
 #else
return 0;



Re: video(1): measure with mono clock (tester wanted)

2018-04-07 Thread Benjamin Baier
On Fri, 6 Apr 2018 09:28:54 -0500
Scott Cheloha  wrote:

> So that your stats stay correct if the system clock is changed.
> 
> This is simple enough to suggest that it's correct at a glance,
> but I have no hardware to test this with.  Can anyone confirm that
> this works?

No regressions.
Greetings Ben

$ /usr/X11R6/bin/video -vvv 
video device /dev/video:
  encodings: yuy2
  frame sizes (width x height, in pixels) and rates (in frames per second):
320x240: 30, 15
352x288: 30, 15
424x240: 30, 15
640x360: 30, 15
640x480: 30, 15
800x448: 15
960x544: 10
1280x720: 10
  controls: brightness, contrast, saturation, hue, gamma, sharpness
Xv adaptor 0, Intel(R) Textured Video:
  encodings: yuy2, uyvy
  max size: 3286x1200
using yuy2 encoding
using frame size 640x480 (614400 bytes)
using default frame rate
video: got ConfigureNotify event1.34, fps: 14.94520
video: got ConfigureNotify event
video: got ConfigureNotify event
video: got KeyPress event: 18.05, fps: 14.40465

run time: 18.330074 seconds
frames grabbed: 265
frames played: 264
played fps: 14.348006

> 
> Index: app/video/video.c
> ===
> RCS file: /cvs/xenocara/app/video/video.c,v
> retrieving revision 1.23
> diff -u -p -r1.23 video.c
> --- app/video/video.c 26 Nov 2016 11:49:15 -  1.23
> +++ app/video/video.c 6 Apr 2018 14:21:26 -
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #include 
> @@ -1635,7 +1636,7 @@ int
>  stream(struct video *vid)
>  {
>   struct xdsp *x = >xdsp;
> - struct timeval tp_start, tp_now, tp_run;
> + struct timespec tp_start, tp_now, tp_run;
>   struct itimerval frit;
>   double run_time;
>   uint8_t *src;
> @@ -1643,7 +1644,7 @@ stream(struct video *vid)
>   int sequence = 20, ret, err, todo, done;
>  
>   /* Guard against uninitialized variable in case no frame is grabbed. */
> - gettimeofday(_start, NULL);
> + clock_gettime(CLOCK_MONOTONIC, _start);
>  
>   if (vid->fps && !vid->nofps) {
>   fus = 100 / vid->fps;
> @@ -1759,21 +1760,21 @@ stream(struct video *vid)
>   frames_played++;
>  
>   if (frames_played == 0)
> - gettimeofday(_start, NULL);
> + clock_gettime(CLOCK_MONOTONIC, _start);
>  
>   if (vid->verbose > 1 && frames_played > 0 &&
>   (frames_played) % sequence == 0) {
> - gettimeofday(_now, NULL);
> - timersub(_now, _start, _run);
> + clock_gettime(CLOCK_MONOTONIC, _now);
> + timespecsub(_now, _start, _run);
>   run_time = tp_run.tv_sec +
> - (double)tp_run.tv_usec / 100;
> + tp_run.tv_nsec / 10.0;
>   fprintf(stderr, "frames: %08ld, seconds: "
>   "%09.2f, fps: %08.5f\r", frames_played,
>   run_time, ((double)frames_played) / run_time);
>   fflush(stderr);
>   }
>   }
> - gettimeofday(_now, NULL);
> + clock_gettime(CLOCK_MONOTONIC, _now);
>  
>   if (vid->fps) {
>   timerclear(_value);
> @@ -1793,8 +1794,8 @@ stream(struct video *vid)
>   fprintf(stderr, "\n");
>  
>   if (vid->verbose > 0) {
> - timersub(_now, _start, _run);
> - run_time = tp_run.tv_sec + (double)tp_run.tv_usec / 100;
> + timespecsub(_now, _start, _run);
> + run_time = tp_run.tv_sec + tp_run.tv_nsec / 10.0;
>   fprintf(stderr, "run time: %f seconds\n", run_time);
>   fprintf(stderr, "frames grabbed: %ld\n", frames_grabbed);
>   fprintf(stderr, "frames played: %ld\n", frames_played + 1);
> 



Re: inteldrm(4) tests needed

2018-01-15 Thread Benjamin Baier
On Mon, 15 Jan 2018 01:02:58 +0100 (CET)
Mark Kettenis  wrote:

> The diff below adopts more of the Linux code to manage i2c
> transactions on hardware supported by inteldrm(4).  The i2c stuff is
> reponsible for detecting panels and monitors, so it is somewhat
> important that this works right.  And the Linux code developed some
> quirks over the years that my rewrite of the code to use OpenBSD APIs
> didn't have.
> 
> So I'm looking for testers.  I'm especially interested in tests of
> external displays on all sorts of connector types (VGA, DVI, HDMI,
> DP).  It would be really great to get some tests on older stuff with
> (S)DVO.  Please let me know if there are regressions or if this fixes
> things that are currently broken.  But all reports are welcome.
> Please include a dmesg and some information about the display and
> connector type.
> 

Thinkpad X220 here, with an external monitor(HDMI) connected throught
a docking station.
The external monitor is now working on the first boot, before I had
to do one suspend/resume cycle to get it recognized, great.
No regression so far, even after some zzz/ZZZ cycles.

Greetings Ben

OpenBSD 6.2-current (GENERIC.MP) #12: Mon Jan 15 10:01:50 CET 2018
b...@x220.home.netzbasis.de:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8451125248 (8059MB)
avail mem = 8188071936 (7808MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.6 @ 0xdae9c000 (64 entries)
bios0: vendor LENOVO version "8DET69WW (1.39 )" date 07/18/2013
bios0: LENOVO 4287CTO
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SLIC SSDT SSDT SSDT HPET APIC MCFG ECDT ASF! TCPA SSDT 
SSDT DMAR UEFI UEFI UEFI
acpi0: wakeup devices LID_(S3) SLPB(S3) IGBE(S4) EXP4(S4) EXP7(S4) EHC1(S3) 
EHC2(S3) HDEF(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2492.26 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT
cpu0: 256KB 64b/line 8-way L2 cache
acpihpet0: recalibrated TSC frequency 2491907253 Hz
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.92 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.92 MHz
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.92 MHz
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpiec0 at acpi0
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEG_)
acpiprt2 at acpi0: bus 2 (EXP1)
acpiprt3 at acpi0: bus 3 (EXP2)
acpiprt4 at acpi0: bus 5 (EXP4)
acpiprt5 at acpi0: bus 13 (EXP5)
acpiprt6 at acpi0: bus -1 (EXP7)
acpicpu0 at acpi0: C3(350@104 io@0x415), C1(1000@1 halt), PSS
acpicpu1 at acpi0: C3(350@104 io@0x415), C1(1000@1 halt), PSS
acpicpu2 at acpi0: C3(350@104 io@0x415), C1(1000@1 halt), PSS
acpicpu3 at acpi0: C3(350@104 io@0x415), C1(1000@1 halt), PSS
acpipwrres0 at acpi0: PUBS, resource for EHC1, EHC2
acpitz0 at acpi0: critical temperature is 99 degC
acpibtn0 at acpi0: LID_
acpibtn1 at acpi0: SLPB
"LEN0020" at acpi0 not configured
acpibat0 at acpi0: BAT0 model "42T4861" serial 12675 type LION oem "SANYO"
acpiac0 at acpi0: AC unit online
acpithinkpad0 at acpi0
"IBM0079" at acpi0 not configured
"PNP0C14" 

Re: snapshot installs

2016-12-30 Thread Benjamin Baier
On Fri, 30 Dec 2016 11:30:10 -0700
Theo de Raadt  wrote:

> I'm wondering if anyone doing an install/upgrade has noticed any
> behaviour changes in the last week...
Did an auto_upgrade with pre-downloaded sets today. Got curious and did one
normal/manual update again from a mirror. No regressions.

> There's a secret diff being tested :-)
Found it. It's in install.sub in bsd.rd's ramdisk.



Re: nologin(8) overhaul

2016-03-13 Thread Benjamin Baier
Ping?
Also #include  could be omitted, because it gets pulled in
by unistd.h.

On Sun, 6 Mar 2016 16:14:14 +0100
Benjamin Baier <program...@netzbasis.de> wrote:

> A /usr/bin/false vs. /sbin/nologin argument led me to nologin(8) so
> here are some suggestions.
> 
> - de-lint
> - return instead of exit()
> - no need to tell an *possible evil* ssh user that pledge(2) failed
> - some more churn/clean up
> 
> Greetings Ben
> 
> Index: nologin.c
> ===
> RCS file: /cvs/src/sbin/nologin/nologin.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 nologin.c
> --- nologin.c 13 Oct 2015 07:10:38 -  1.6
> +++ nologin.c 6 Mar 2016 08:46:24 -
> @@ -26,19 +26,14 @@
>   */
>  
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
>  
> -/* Distinctly different from _PATH_NOLOGIN. */
> -#define _PATH_NOLOGIN_TXT"/etc/nologin.txt"
> -
>  #define DEFAULT_MESG "This account is currently not available.\n"
>  
> -/*ARGSUSED*/
>  int
>  main(int argc, char *argv[])
>  {
> @@ -47,17 +42,16 @@ main(int argc, char *argv[])
>   char nbuf[BUFSIZ];
>  
>   if (pledge("stdio rpath", NULL) == -1)
> - err(1, "pledge");
> + return (1);
>  
> - nfd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
> - if (nfd < 0) {
> + nfd = open("/etc/nologin.txt", O_RDONLY);
> + if (nfd < 0)
>   write(STDOUT_FILENO, DEFAULT_MESG, strlen(DEFAULT_MESG));
> - exit (1);
> + else {
> + while ((nrd = read(nfd, nbuf, sizeof(nbuf))) != -1 && nrd != 0)
> + write(STDOUT_FILENO, nbuf, nrd);
> + close (nfd);
>   }
>  
> - while ((nrd = read(nfd, nbuf, sizeof(nbuf))) != -1 && nrd != 0)
> - write(STDOUT_FILENO, nbuf, nrd);
> - close (nfd);
> -
> - exit (1);
> + return (1);
>  }
> 



nologin(8) overhaul

2016-03-06 Thread Benjamin Baier
A /usr/bin/false vs. /sbin/nologin argument led me to nologin(8) so
here are some suggestions.

- de-lint
- return instead of exit()
- no need to tell an *possible evil* ssh user that pledge(2) failed
- some more churn/clean up

Greetings Ben

Index: nologin.c
===
RCS file: /cvs/src/sbin/nologin/nologin.c,v
retrieving revision 1.6
diff -u -p -r1.6 nologin.c
--- nologin.c   13 Oct 2015 07:10:38 -  1.6
+++ nologin.c   6 Mar 2016 08:46:24 -
@@ -26,19 +26,14 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
-/* Distinctly different from _PATH_NOLOGIN. */
-#define _PATH_NOLOGIN_TXT  "/etc/nologin.txt"
-
 #define DEFAULT_MESG   "This account is currently not available.\n"
 
-/*ARGSUSED*/
 int
 main(int argc, char *argv[])
 {
@@ -47,17 +42,16 @@ main(int argc, char *argv[])
char nbuf[BUFSIZ];
 
if (pledge("stdio rpath", NULL) == -1)
-   err(1, "pledge");
+   return (1);
 
-   nfd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
-   if (nfd < 0) {
+   nfd = open("/etc/nologin.txt", O_RDONLY);
+   if (nfd < 0)
write(STDOUT_FILENO, DEFAULT_MESG, strlen(DEFAULT_MESG));
-   exit (1);
+   else {
+   while ((nrd = read(nfd, nbuf, sizeof(nbuf))) != -1 && nrd != 0)
+   write(STDOUT_FILENO, nbuf, nrd);
+   close (nfd);
}
 
-   while ((nrd = read(nfd, nbuf, sizeof(nbuf))) != -1 && nrd != 0)
-   write(STDOUT_FILENO, nbuf, nrd);
-   close (nfd);
-
-   exit (1);
+   return (1);
 }



Re: I have a mirror testing program for you. - Mirror down

2016-01-20 Thread Benjamin Baier
Important thing first, the mirror http://openbsd.cs.fau.de/pub/OpenBSD/
seems to be down.

On Tue, 19 Jan 2016 22:19:42 -0600
Luke Small  wrote:

> I have a 500 line program I wrote that reads openbsd.org.ftp.html and
> scraps off the html and ftp mirrors, records them all without redundancies
> as http mirrors in memory and downloads the appropriate version and machine
> architecture's SHA256 in the package folder. It tests all the mirrors for
> time, one at a time and uses kqueue to kill any laggy ftp calls. It uses
> ftp() calls for all its networking, so it shouldn't be too much of a
> security issue I'd guess. It writes the top 8 mirrors into /etc/pkg.conf it
> erases all the installpath entries while leaving everything else in the
> file. It can run as an unprivileged user, but of course it won't rewrite
> /etc/pkg.conf
> -Luke N Small
My quick-n-dirty script[1] tells me as long as I use
a mirror geographically close to me, I'll be fine.
- time diff in same country between different mirrors <=10%
- time diff same server tested multiple times <=10%
- time diff local vs. halfway around the earth >100% to <300%


[1] pkg_ping.sh
#!/bin/sh
#usage: ./pkg_ping.sh uk
#to test all the uk servers.
TMPFILE=/tmp/pkg_ping.tmp
SHATMP=/tmp/pkg_ping.sha

if [ ! -f ${TMPFILE} ]
then
ftp -o - http://www.openbsd.org/build/mirrors.dat |\
grep -e ^GZ -e ^UH |\
grep -B1 -e ^UH |\
grep -e ^GZ -e ^UH |\
cut -f 2- > ${TMPFILE}
fi

grep -A1 -e "^$1" ${TMPFILE} | grep http |\
while read line
do
echo trying ${line}
time ftp -o ${SHATMP} ${line}/snapshots/packages/amd64/SHA256
done



npppd(8): sync option parsing with other userland utils

2015-11-08 Thread Benjamin Baier
Hello tech@

This patch brings npppd(8)'s option parsing in sync with all the other userland 
utils that don't recognize -h for help/usage (except for some games, still).

Also exit(3) at the end of the usage() function and mark it as __dead.

Greetings Ben

Index: npppd/npppd.8
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd.8,v
retrieving revision 1.5
diff -u -p -r1.5 npppd.8
--- npppd/npppd.8   29 Jan 2013 15:42:20 -  1.5
+++ npppd/npppd.8   8 Nov 2015 20:30:35 -
@@ -23,7 +23,7 @@
 .Nd new Point-to-Point Protocol daemon
 .Sh SYNOPSIS
 .Nm npppd
-.Op Fl dhn
+.Op Fl dn
 .Op Fl f Ar config_file
 .Sh DESCRIPTION
 .Nm
@@ -38,8 +38,6 @@ will run in the foreground and log to
 .Em stderr .
 .It Fl f Ar config_file
 Specify an alternative configuration file.
-.It Fl h
-Show the usage.
 .It Fl n
 Configtest mode.
 Only check the configuration file for validity.
Index: npppd/npppd.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd.c,v
retrieving revision 1.41
diff -u -p -r1.41 npppd.c
--- npppd/npppd.c   24 Jun 2015 04:57:55 -  1.41
+++ npppd/npppd.c   8 Nov 2015 20:54:15 -
@@ -145,7 +145,7 @@ main(int argc, char *argv[])
const char*npppd_conf0 = DEFAULT_NPPPD_CONF;
struct passwd *pw;

-   while ((ch = getopt(argc, argv, "nf:dh")) != -1) {
+   while ((ch = getopt(argc, argv, "nf:d")) != -1) {
switch (ch) {
case 'n':
nflag = 1;
@@ -157,17 +157,14 @@ main(int argc, char *argv[])
debuglevel++;
runasdaemon = 0;
break;
-   case '?':
-   case 'h':
+   default:
usage();
-   exit(1);
}
}
argc -= optind;
argv += optind;
if (argc != 0) {
usage();
-   exit(1);
}
if (nflag) {
debuglevel++;
@@ -225,10 +222,11 @@ main(int argc, char *argv[])
exit((!stop_by_error)? EXIT_SUCCESS : EXIT_FAILURE);
 }

-static void
-usage()
+static __dead void
+usage(void)
 {
-   fprintf(stderr, "usage: npppd [-dhn] [-f config_file]\n");
+   fprintf(stderr, "usage: npppd [-dn] [-f config_file]\n");
+   exit(1);
 }

 /** Returns the singleton npppd instance */



remove superfluous case '?': from /sbin utils

2015-11-08 Thread Benjamin Baier
Hello tech@

I cleaned up and split up my former diff[0] for removing superfluous
case '?': /*FALLTHROUGH*/
default:
usage();

Also removes one unnecessary break;

This is for /sbin, more to come if there are any takers?
Greetings Ben

[0] https://marc.info/?l=openbsd-tech=143387215328391=2

Index: disklabel/disklabel.c
===
RCS file: /cvs/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.211
diff -u -p -r1.211 disklabel.c
--- disklabel/disklabel.c   17 Oct 2015 13:27:08 -  1.211
+++ disklabel/disklabel.c   8 Nov 2015 09:38:05 -
@@ -169,7 +169,6 @@ main(int argc, char *argv[])
case 'v':
verbose = 1;
break;
-   case '?':
default:
usage();
}
Index: dmesg/dmesg.c
===
RCS file: /cvs/src/sbin/dmesg/dmesg.c,v
retrieving revision 1.27
diff -u -p -r1.27 dmesg.c
--- dmesg/dmesg.c   9 Oct 2015 01:37:06 -   1.27
+++ dmesg/dmesg.c   8 Nov 2015 09:38:05 -
@@ -81,7 +81,6 @@ main(int argc, char *argv[])
case 'N':
nlistf = optarg;
break;
-   case '?':
default:
usage();
}
Index: dumpfs/dumpfs.c
===
RCS file: /cvs/src/sbin/dumpfs/dumpfs.c,v
retrieving revision 1.32
diff -u -p -r1.32 dumpfs.c
--- dumpfs/dumpfs.c 20 Jan 2015 18:22:21 -  1.32
+++ dumpfs/dumpfs.c 8 Nov 2015 09:38:05 -
@@ -89,7 +89,6 @@ main(int argc, char *argv[])
case 'm':
domarshal = 1;
break;
-   case '?':
default:
usage();
}
Index: fsck/fsck.c
===
RCS file: /cvs/src/sbin/fsck/fsck.c,v
retrieving revision 1.37
diff -u -p -r1.37 fsck.c
--- fsck/fsck.c 29 May 2015 15:57:36 -  1.37
+++ fsck/fsck.c 8 Nov 2015 09:38:05 -
@@ -163,7 +163,6 @@ main(int argc, char *argv[])
filter = NET_FILTER;
break;

-   case '?':
default:
usage();
/* NOTREACHED */
Index: growfs/growfs.c
===
RCS file: /cvs/src/sbin/growfs/growfs.c,v
retrieving revision 1.40
diff -u -p -r1.40 growfs.c
--- growfs/growfs.c 20 Aug 2015 22:02:21 -  1.40
+++ growfs/growfs.c 8 Nov 2015 09:38:05 -
@@ -1937,8 +1937,6 @@ main(int argc, char **argv)
case 'y':
ExpertFlag = 1;
break;
-   case '?':
-   /* FALLTHROUGH */
default:
usage();
}
Index: isakmpd/isakmpd.c
===
RCS file: /cvs/src/sbin/isakmpd/isakmpd.c,v
retrieving revision 1.103
diff -u -p -r1.103 isakmpd.c
--- isakmpd/isakmpd.c   20 Aug 2015 22:02:21 -  1.103
+++ isakmpd/isakmpd.c   8 Nov 2015 09:38:05 -
@@ -210,7 +210,6 @@ parse_args(int argc, char *argv[])
verbose_logging = 1;
break;

-   case '?':
default:
usage();
}
Index: mknod/mknod.c
===
RCS file: /cvs/src/sbin/mknod/mknod.c,v
retrieving revision 1.18
diff -u -p -r1.18 mknod.c
--- mknod/mknod.c   27 Mar 2010 09:10:02 -  1.18
+++ mknod/mknod.c   8 Nov 2015 09:38:05 -
@@ -76,7 +76,6 @@ main(int argc, char *argv[])
mode = getmode(set, DEFFILEMODE);
free(set);
break;
-   case '?':
default:
usage(ismkfifo);
}
Index: mount/mount.c
===
RCS file: /cvs/src/sbin/mount/mount.c,v
retrieving revision 1.60
diff -u -p -r1.60 mount.c
--- mount/mount.c   16 Jan 2015 06:39:59 -  1.60
+++ mount/mount.c   8 Nov 2015 09:38:05 -
@@ -157,7 +157,6 @@ main(int argc, char * const argv[])
if (!hasopt(options, "rw"))
options = catopt(options, "rw");
break;
-   case '?':
default:
usage();
/* NOTREACHED */
Index: mount_cd9660/mount_cd9660.c
===
RCS file: /cvs/src/sbin/mount_cd9660/mount_cd9660.c,v
retrieving revision 1.21
diff -u 

Part2: remove superfluous case '?': from /usr/bin utils

2015-11-08 Thread Benjamin Baier
Hello tech@

Part 2 for /usr/bin
Also adjust getopt(3)'s optstring in midiplay.c and usbhid.c

Greetings Ben

Index: biff/biff.c
===
RCS file: /cvs/src/usr.bin/biff/biff.c,v
retrieving revision 1.13
diff -u -p -r1.13 biff.c
--- biff/biff.c 12 Oct 2015 20:03:24 -  1.13
+++ biff/biff.c 8 Nov 2015 09:38:05 -
@@ -54,7 +54,6 @@ main(int argc, char *argv[])
 
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
-   case '?':
default:
usage();
}
Index: cal/cal.c
===
RCS file: /cvs/src/usr.bin/cal/cal.c,v
retrieving revision 1.30
diff -u -p -r1.30 cal.c
--- cal/cal.c   9 Oct 2015 01:37:06 -   1.30
+++ cal/cal.c   8 Nov 2015 09:38:05 -
@@ -168,7 +168,6 @@ main(int argc, char *argv[])
case 'y':
yflag = 1;
break;
-   case '?':
default:
usage();
}
Index: cap_mkdb/cap_mkdb.c
===
RCS file: /cvs/src/usr.bin/cap_mkdb/cap_mkdb.c,v
retrieving revision 1.20
diff -u -p -r1.20 cap_mkdb.c
--- cap_mkdb/cap_mkdb.c 29 Oct 2015 02:58:00 -  1.20
+++ cap_mkdb/cap_mkdb.c 8 Nov 2015 09:38:05 -
@@ -92,7 +92,6 @@ main(int argc, char *argv[])
case 'i':
info = 1;
break;
-   case '?':
default:
usage();
}
Index: chpass/chpass.c
===
RCS file: /cvs/src/usr.bin/chpass/chpass.c,v
retrieving revision 1.41
diff -u -p -r1.41 chpass.c
--- chpass/chpass.c 16 Jan 2015 06:40:06 -  1.41
+++ chpass/chpass.c 8 Nov 2015 09:38:05 -
@@ -103,7 +103,6 @@ main(int argc, char *argv[])
force_yp = 1;
break;
 #endif
-   case '?':
default:
usage();
}
Index: cmp/cmp.c
===
RCS file: /cvs/src/usr.bin/cmp/cmp.c,v
retrieving revision 1.13
diff -u -p -r1.13 cmp.c
--- cmp/cmp.c   10 Oct 2015 05:35:22 -  1.13
+++ cmp/cmp.c   8 Nov 2015 09:38:05 -
@@ -68,7 +68,6 @@ main(int argc, char *argv[])
case 's':   /* silent run */
sflag = 1;
break;
-   case '?':
default:
usage();
}
Index: col/col.c
===
RCS file: /cvs/src/usr.bin/col/col.c,v
retrieving revision 1.19
diff -u -p -r1.19 col.c
--- col/col.c   9 Oct 2015 01:37:06 -   1.19
+++ col/col.c   8 Nov 2015 09:38:05 -
@@ -139,7 +139,6 @@ main(int argc, char *argv[])
case 'x':   /* do not compress spaces into tabs */
compress_spaces = 0;
break;
-   case '?':
default:
usage();
}
Index: colrm/colrm.c
===
RCS file: /cvs/src/usr.bin/colrm/colrm.c,v
retrieving revision 1.11
diff -u -p -r1.11 colrm.c
--- colrm/colrm.c   9 Oct 2015 01:37:06 -   1.11
+++ colrm/colrm.c   8 Nov 2015 09:38:05 -
@@ -57,7 +57,6 @@ main(int argc, char *argv[])
 
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
-   case '?':
default:
usage();
}
Index: column/column.c
===
RCS file: /cvs/src/usr.bin/column/column.c,v
retrieving revision 1.22
diff -u -p -r1.22 column.c
--- column/column.c 3 Nov 2015 04:55:44 -   1.22
+++ column/column.c 8 Nov 2015 09:38:05 -
@@ -96,7 +96,6 @@ main(int argc, char *argv[])
case 'x':
xflag = 1;
break;
-   case '?':
default:
usage();
}
Index: comm/comm.c
===
RCS file: /cvs/src/usr.bin/comm/comm.c,v
retrieving revision 1.10
diff -u -p -r1.10 comm.c
--- comm/comm.c 9 Oct 2015 01:37:07 -   1.10
+++ comm/comm.c 8 Nov 2015 09:38:05 -
@@ -80,7 +80,6 @@ main(int argc, char *argv[])
case 'f':
compare = strcasecmp;
break;
-   case '?':
default:
usage();
}
Index: ctags/ctags.c
===

Part3: remove superfluous case '?': from /usr/sbin utils

2015-11-08 Thread Benjamin Baier
Hello tech@

Part 3 for /usr/sbin
Also adjust getopt(3)'s optstring in usbdevs.c
and remove some unnecessary break;

Greetings Ben

Index: ac/ac.c
===
RCS file: /cvs/src/usr.sbin/ac/ac.c,v
retrieving revision 1.24
diff -u -p -r1.24 ac.c
--- ac/ac.c 12 Oct 2015 02:02:00 -  1.24
+++ ac/ac.c 8 Nov 2015 20:09:57 -
@@ -223,10 +223,8 @@ main(int argc, char *argv[])
case 'w':
fp = file(optarg);
break;
-   case '?':
default:
usage();
-   break;
}
}
if (optind < argc) {
Index: accton/accton.c
===
RCS file: /cvs/src/usr.sbin/accton/accton.c,v
retrieving revision 1.8
diff -u -p -r1.8 accton.c
--- accton/accton.c 27 Oct 2009 23:59:50 -  1.8
+++ accton/accton.c 8 Nov 2015 09:39:22 -
@@ -50,7 +50,6 @@ main(int argc, char *argv[])

while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
-   case '?':
default:
usage();
}
Index: apmd/apmd.c
===
RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.77
diff -u -p -r1.77 apmd.c
--- apmd/apmd.c 11 Oct 2015 20:23:49 -  1.77
+++ apmd/apmd.c 8 Nov 2015 09:39:22 -
@@ -402,7 +402,6 @@ main(int argc, char *argv[])
doperf = PERF_MANUAL;
setperfpolicy("high");
break;
-   case '?':
default:
usage();
}
Index: dev_mkdb/dev_mkdb.c
===
RCS file: /cvs/src/usr.sbin/dev_mkdb/dev_mkdb.c,v
retrieving revision 1.15
diff -u -p -r1.15 dev_mkdb.c
--- dev_mkdb/dev_mkdb.c 16 Oct 2015 13:37:44 -  1.15
+++ dev_mkdb/dev_mkdb.c 8 Nov 2015 09:39:22 -
@@ -66,7 +66,6 @@ main(int argc, char *argv[])

while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
-   case '?':
default:
usage();
}
Index: eeprom/main.c
===
RCS file: /cvs/src/usr.sbin/eeprom/main.c,v
retrieving revision 1.22
diff -u -p -r1.22 main.c
--- eeprom/main.c   11 Mar 2015 18:12:27 -  1.22
+++ eeprom/main.c   8 Nov 2015 09:39:22 -
@@ -145,7 +145,6 @@ main(int argc, char *argv[])
break;
 #endif /* __sparc__ && !__sparc64__ */

-   case '?':
default:
usage();
}
Index: fdformat/fdformat.c
===
RCS file: /cvs/src/usr.sbin/fdformat/fdformat.c,v
retrieving revision 1.20
diff -u -p -r1.20 fdformat.c
--- fdformat/fdformat.c 18 Apr 2015 18:28:38 -  1.20
+++ fdformat/fdformat.c 8 Nov 2015 09:39:22 -
@@ -253,7 +253,7 @@ main(int argc, char *argv[])
verify_only = 1;
break;

-   case '?': default:
+   default:
usage();
}

Index: hotplugd/hotplugd.c
===
RCS file: /cvs/src/usr.sbin/hotplugd/hotplugd.c,v
retrieving revision 1.12
diff -u -p -r1.12 hotplugd.c
--- hotplugd/hotplugd.c 10 Jan 2010 13:20:41 -  1.12
+++ hotplugd/hotplugd.c 8 Nov 2015 09:39:22 -
@@ -66,7 +66,6 @@ main(int argc, char *argv[])
case 'd':
device = optarg;
break;
-   case '?':
default:
usage();
/* NOTREACHED */
Index: inetd/inetd.c
===
RCS file: /cvs/src/usr.sbin/inetd/inetd.c,v
retrieving revision 1.149
diff -u -p -r1.149 inetd.c
--- inetd/inetd.c   1 Nov 2015 19:59:28 -   1.149
+++ inetd/inetd.c   8 Nov 2015 09:39:22 -
@@ -316,7 +316,6 @@ main(int argc, char *argv[])
optarg);
break;
}
-   case '?':
default:
fprintf(stderr,
"usage: inetd [-d] [-R rate] 
[configuration_file]\n");
Index: iostat/iostat.c
===
RCS file: /cvs/src/usr.sbin/iostat/iostat.c,v
retrieving revision 1.39
diff -u -p -r1.39 iostat.c
--- iostat/iostat.c 23 Oct 2015 08:21:27 -  1.39
+++ iostat/iostat.c 8 Nov 2015 09:39:22 -
@@ -150,7 +150,6 @@ main(int argc, char *argv[])
if (errstr)
 

ahci.c memory leak in error path

2015-10-02 Thread Benjamin Baier
Fix memory leak in error path.
Found by llvm/scan-build.

Also port (sc->sc_ports[port]) was not assigned, so "goto freeport;"
seems wrong.

Index: ahci.c
===
RCS file: /cvs/src/sys/dev/ic/ahci.c,v
retrieving revision 1.22
diff -u -p -r1.22 ahci.c
--- ahci.c  27 Aug 2015 18:47:29 -  1.22
+++ ahci.c  26 Sep 2015 09:29:57 -
@@ -460,7 +460,8 @@ ahci_port_alloc(struct ahci_softc *sc, u
if (ap->ap_err_scratch == NULL) {
printf("%s: unable to allocate DMA scratch buf for port %d\n",
DEVNAME(sc), port);
-   goto freeport;
+   free(ap, M_DEVBUF, sizeof(*ap));
+   goto reterr;
}
 
 #ifdef AHCI_DEBUG



clean the tree from superfluous case '?': /* FALLTHROUGH */

2015-06-09 Thread Benjamin Baier
Hello tech@

delete case '?': /* FALLTHROUGH */ where it is already handled 
by default: usage();.

Rarely also adjust getopt(3)'s optstring.



Index: bin/pax/options.c
===
RCS file: /cvs/src/bin/pax/options.c,v
retrieving revision 1.91
diff -u -p -r1.91 options.c
--- bin/pax/options.c   18 May 2015 20:26:16 -  1.91
+++ bin/pax/options.c   9 Jun 2015 17:27:56 -
@@ -1307,7 +1307,6 @@ cpio_options(int argc, char **argv)
 */
frmt = (fsub[F_OCPIO]);
break;
-   case '?':
default:
cpio_usage();
break;
Index: games/arithmetic/arithmetic.c
===
RCS file: /cvs/src/games/arithmetic/arithmetic.c,v
retrieving revision 1.18
diff -u -p -r1.18 arithmetic.c
--- games/arithmetic/arithmetic.c   29 Aug 2013 20:22:09 -  1.18
+++ games/arithmetic/arithmetic.c   9 Jun 2015 17:28:09 -
@@ -116,7 +116,6 @@ main(int argc, char *argv[])
if ((rangemax = atoi(optarg)) = 0)
errx(1, invalid range.);
break;
-   case '?':
case 'h':
default:
usage();
Index: games/banner/banner.c
===
RCS file: /cvs/src/games/banner/banner.c,v
retrieving revision 1.17
diff -u -p -r1.17 banner.c
--- games/banner/banner.c   10 Feb 2015 13:50:58 -  1.17
+++ games/banner/banner.c   9 Jun 2015 17:28:09 -
@@ -1030,7 +1030,7 @@ main(int argc, char *argv[])
if (width = 0 || width  DWIDTH)
errx(1, illegal argument for -w option);
break;
-   case '?': case 'h':
+   case 'h':
default:
(void)fprintf(stderr,
usage: banner [-w width] message ...\n);
Index: games/boggle/boggle/bog.c
===
RCS file: /cvs/src/games/boggle/boggle/bog.c,v
retrieving revision 1.24
diff -u -p -r1.24 bog.c
--- games/boggle/boggle/bog.c   4 Dec 2014 06:12:33 -   1.24
+++ games/boggle/boggle/bog.c   9 Jun 2015 17:28:09 -
@@ -117,7 +117,6 @@ main(int argc, char *argv[])
if ((minlength = atoi(optarg))  3)
errx(1, min word length must be  2);
break;
-   case '?':
default:
usage();
}
Index: games/cribbage/crib.c
===
RCS file: /cvs/src/games/cribbage/crib.c,v
retrieving revision 1.18
diff -u -p -r1.18 crib.c
--- games/cribbage/crib.c   12 Mar 2015 02:19:10 -  1.18
+++ games/cribbage/crib.c   9 Jun 2015 17:28:09 -
@@ -63,7 +63,6 @@ main(int argc, char *argv[])
case 'r':
rflag = TRUE;
break;
-   case '?':
default:
(void) fprintf(stderr, usage: cribbage [-emqr]\n);
exit(1);
Index: games/factor/factor.c
===
RCS file: /cvs/src/games/factor/factor.c,v
retrieving revision 1.19
diff -u -p -r1.19 factor.c
--- games/factor/factor.c   27 Oct 2009 23:59:24 -  1.19
+++ games/factor/factor.c   9 Jun 2015 17:28:09 -
@@ -89,7 +89,6 @@ main(int argc, char *argv[])
 
while ((ch = getopt(argc, argv, )) != -1)
switch (ch) {
-   case '?':
default:
usage();
}
Index: games/fish/fish.c
===
RCS file: /cvs/src/games/fish/fish.c,v
retrieving revision 1.17
diff -u -p -r1.17 fish.c
--- games/fish/fish.c   18 Feb 2015 23:20:45 -  1.17
+++ games/fish/fish.c   9 Jun 2015 17:28:09 -
@@ -92,7 +92,6 @@ main(int argc, char *argv[])
case 'p':
promode = 1;
break;
-   case '?':
case 'h':
default:
usage();
Index: games/fortune/fortune/fortune.c
===
RCS file: /cvs/src/games/fortune/fortune/fortune.c,v
retrieving revision 1.42
diff -u -p -r1.42 fortune.c
--- games/fortune/fortune/fortune.c 6 Feb 2015 10:50:48 -   1.42
+++ games/fortune/fortune/fortune.c 9 Jun 2015 17:28:09 -
@@ -303,7 +303,6 @@ getargs(int argc, char *argv[])
case 'i':   /* case-insensitive 

Re: clean the tree from superfluous case '?': /* FALLTHROUGH */

2015-06-09 Thread Benjamin Baier
On Tue, 9 Jun 2015 14:01:01 -0700
patrick keshishian sids...@boxsoft.com wrote:

 Hi,
 
 On Tue, Jun 09, 2015 at 07:46:20PM +0200, Benjamin Baier wrote:
  Hello tech@
  
  delete case '?': /* FALLTHROUGH */ where it is already handled 
  by default: usage();.
 
 Not quite sure it is correct to remove the '?' case from
 npppd.c, since there is no 'default' case.
Best to leave it out. Yes you are right this alters behaviour (usage not 
printed) when invalid option arguments are passed. Had it on the list to
revisit later and add a default case.

 Also, if the idea is to remove cases which simply fall through
 'default', these few (10) have 'h' cases that do same (judging
 from your diff):
 
  RCS file: /cvs/src/games/arithmetic/arithmetic.c,v
  RCS file: /cvs/src/games/banner/banner.c,v
  RCS file: /cvs/src/games/fish/fish.c,v
  RCS file: /cvs/src/games/grdc/grdc.c,v
  RCS file: /cvs/src/games/hangman/main.c,v
  RCS file: /cvs/src/games/morse/morse.c,v
  RCS file: /cvs/src/games/number/number.c,v
  RCS file: /cvs/src/games/ppt/ppt.c,v
  RCS file: /cvs/src/games/snake/snake.c,v
  RCS file: /cvs/src/games/worms/worms.c,v
I was focusing on case '?', and because 'h' is a valid option argument i
decided not to delete the case 'h', for now.
But i'm happy to add them to the patch, if requested.
 
 --patrick
 
 
 ...
  Index: games/arithmetic/arithmetic.c
  ===
  RCS file: /cvs/src/games/arithmetic/arithmetic.c,v
  retrieving revision 1.18
  diff -u -p -r1.18 arithmetic.c
  --- games/arithmetic/arithmetic.c   29 Aug 2013 20:22:09 -  1.18
  +++ games/arithmetic/arithmetic.c   9 Jun 2015 17:28:09 -
  @@ -116,7 +116,6 @@ main(int argc, char *argv[])
  if ((rangemax = atoi(optarg)) = 0)
  errx(1, invalid range.);
  break;
  -   case '?':
  case 'h':
  default:
  usage();
  Index: games/banner/banner.c
  ===
  RCS file: /cvs/src/games/banner/banner.c,v
  retrieving revision 1.17
  diff -u -p -r1.17 banner.c
  --- games/banner/banner.c   10 Feb 2015 13:50:58 -  1.17
  +++ games/banner/banner.c   9 Jun 2015 17:28:09 -
  @@ -1030,7 +1030,7 @@ main(int argc, char *argv[])
  if (width = 0 || width  DWIDTH)
  errx(1, illegal argument for -w option);
  break;
  -   case '?': case 'h':
  +   case 'h':
  default:
  (void)fprintf(stderr,
  usage: banner [-w width] message ...\n);
 ...
  ===
  RCS file: /cvs/src/games/fish/fish.c,v
  retrieving revision 1.17
  diff -u -p -r1.17 fish.c
  --- games/fish/fish.c   18 Feb 2015 23:20:45 -  1.17
  +++ games/fish/fish.c   9 Jun 2015 17:28:09 -
  @@ -92,7 +92,6 @@ main(int argc, char *argv[])
  case 'p':
  promode = 1;
  break;
  -   case '?':
  case 'h':
  default:
  usage();
  }
 ...
  Index: games/grdc/grdc.c
  ===
  RCS file: /cvs/src/games/grdc/grdc.c,v
  retrieving revision 1.19
  diff -u -p -r1.19 grdc.c
  --- games/grdc/grdc.c   19 Nov 2014 03:27:45 -  1.19
  +++ games/grdc/grdc.c   9 Jun 2015 17:28:09 -
  @@ -77,7 +77,6 @@ main(int argc, char *argv[])
  scrol = 1;
  break;
  case 'h':
  -   case '?':
  default:
  usage();
  }
  Index: games/hangman/main.c
  ===
  RCS file: /cvs/src/games/hangman/main.c,v
  retrieving revision 1.12
  diff -u -p -r1.12 main.c
  --- games/hangman/main.c7 Feb 2015 01:37:30 -   1.12
  +++ games/hangman/main.c9 Jun 2015 17:28:09 -
  @@ -56,7 +56,6 @@ main(int argc, char *argv[])
  Dict_name = _PATH_KSYMS;
  break;
  case 'h':
  -   case '?':
  default:
  usage();
  }
  Index: games/morse/morse.c
  ===
  RCS file: /cvs/src/games/morse/morse.c,v
  retrieving revision 1.15
  diff -u -p -r1.15 morse.c
  --- games/morse/morse.c 27 Nov 2013 13:32:02 -  1.15
  +++ games/morse/morse.c 9 Jun 2015 17:28:09 -
  @@ -120,7 +120,7 @@ main(int argc, char *argv[])
  case 's':
  sflag = 1;
  break;
  -   case '?': case 'h':
  +   case 'h':
  default:
  fprintf(stderr, usage: morse [-d | -s] [string 
  ...]\n

[PATCH] libcrypto: initialize pointer

2015-05-29 Thread Benjamin Baier
Hello tech@

buf.data is not initialized up front, which may lead to free(3)'ing a
garbage pointer. Found by llvm/scan-build.
Also free(3) handles NULL. No need to check.

Index: tasn_dec.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/asn1/tasn_dec.c,v
retrieving revision 1.26
diff -u -p -r1.26 tasn_dec.c
--- tasn_dec.c  19 Mar 2015 14:00:22 -  1.26
+++ tasn_dec.c  27 May 2015 18:40:34 -
@@ -669,6 +669,8 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval,
const unsigned char *cont = NULL;
long len;
 
+   buf.data = NULL;
+
if (!pval) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
return 0; /* Should never happen */
@@ -783,7 +785,7 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval,
ret = 1;
 
 err:
-   if (free_cont  buf.data)
+   if (free_cont)
free(buf.data);
return ret;
 }



[PATCH 2/3] fsck(8): no need to check for NULL before free(3)

2015-05-29 Thread Benjamin Baier
No need to check for NULL before free(3)

Fri May 29 10:59:23 CEST 2015
/git/hellfish/src/sbin/fsck
Index: fsck.c
===
RCS file: /cvs/src/sbin/fsck/fsck.c,v
retrieving revision 1.35
diff -u -p -r1.35 fsck.c
--- fsck.c  18 Apr 2015 18:28:37 -  1.35
+++ fsck.c  29 May 2015 08:59:01 -
@@ -287,8 +287,7 @@ checkfs(const char *vfstype, const char
switch (pid = fork()) {
case -1:/* Error. */
warn(fork);
-   if (optbuf)
-   free(optbuf);
+   free(optbuf);
free(argv);
return (1);

@@ -320,8 +319,7 @@ checkfs(const char *vfstype, const char
/* NOTREACHED */

default:/* Parent. */
-   if (optbuf)
-   free(optbuf);
+   free(optbuf);
free(argv);

if (pidp) {
@@ -439,7 +437,7 @@ catopt(char *s0, const char *s1, int fr)
} else
cp = estrdup(s1);

-   if (s0  fr)
+   if (fr)
free(s0);
return (cp);
 }

--- fsutil.c.p1 Fri May 29 11:01:25 2015
+++ fsutil.cFri May 29 11:02:18 2015
@@ -258,8 +258,7 @@ ereallocarray(void *p, size_t n, size_t s)
}
newp = reallocarray(p, n, s);
if (newp == NULL) {
-   if (p)
-   free(p);
+   free(p);
err(1, reallocarray failed);
}
return newp;



[PATCH 1/3] fsck(8): adjust error logic for recent erealloc to ereallocarray switch

2015-05-29 Thread Benjamin Baier
Hello tech@

adjust error logic for zero sized allocations and the error messages for 
the recent erealloc to ereallocarray switch.

A follow up diff will clean up all if (x) free(x); statements.

Index: fsutil.c
===
RCS file: /cvs/src/sbin/fsck/fsutil.c,v
retrieving revision 1.20
diff -u -p -r1.20 fsutil.c
--- fsutil.c16 Jan 2015 06:39:57 -  1.20
+++ fsutil.c29 May 2015 08:48:57 -
@@ -252,13 +252,15 @@ ereallocarray(void *p, size_t n, size_t
 {
void *newp;

-   if (s == 0)
-   err(1, realloc failed);
+   if (n == 0 || s == 0) {
+   free(p);
+   err(1, reallocarray failed);
+   }
newp = reallocarray(p, n, s);
if (newp == NULL) {
if (p)
free(p);
-   err(1, realloc failed);
+   err(1, reallocarray failed);
}
return newp;
 }



[PATCH 3/3] fsck(8): no need to assign variable twice

2015-05-29 Thread Benjamin Baier
This got me looking at the code first.

No need to assign argc and maxargc twice.
Found by llvm/scan-build

--- fsck.c.p1   Fri May 29 11:01:25 2015
+++ fsck.c  Fri May 29 11:02:18 2015
@@ -449,9 +447,6 @@ mangle(char *opts, int *argcp, const cha
char *p, *s;
int argc = *argcp, maxargc = *maxargcp;
const char **argv = *argvp;
-
-   argc = *argcp;
-   maxargc = *maxargcp;

for (s = opts; (p = strsep(s, ,)) != NULL;) {
/* always leave space for one more argument and the NULL */



[PATCH] sync renice(8) with manpage and POSIX and other BSDs

2015-03-20 Thread Benjamin Baier
Hello tech@,
this bugs me for a while now, so I'm sendig this diff in for consideration.
Brings renice(8) manpage and code and POSIX definition more in sync by:
- makeing the code increment the priority instead of setting it when -n is used.
- documenting the backwards compatible set priority option
- makeing set priority and -n mutually exclusive
- makeing set priority accept +10 as a valid priority

Also this brings OpenBSD's renice more in sync with other BSDs.

Index: renice.8
===
RCS file: /cvs/src/usr.bin/renice/renice.8,v
retrieving revision 1.23
diff -u -p -r1.23 renice.8
--- renice.823 May 2014 06:40:57 -  1.23
+++ renice.820 Mar 2015 12:31:43 -
@@ -37,6 +37,20 @@
 .Nd alter priority of running processes
 .Sh SYNOPSIS
 .Nm renice
+.Ar priority
+.Oo
+.Op Fl g
+.Ar pgrp ...
+.Oc
+.Oo
+.Op Fl p
+.Ar pid ...
+.Oc
+.Oo
+.Op Fl u
+.Ar user ...
+.Oc
+.Nm renice
 .Fl n Ar increment
 .Oo
 .Op Fl g
@@ -131,7 +145,7 @@ utility is compliant with the
 specification,
 except the way in which processes are specified differs.
 .Pp
-The historical behavior of passing the increment as the first
+The historical behavior of passing the priority as the first
 argument is supported for backwards compatibility.
 .Sh HISTORY
 The
Index: renice.c
===
RCS file: /cvs/src/usr.bin/renice/renice.c,v
retrieving revision 1.16
diff -u -p -r1.16 renice.c
--- renice.c15 Nov 2013 22:20:04 -  1.16
+++ renice.c20 Mar 2015 12:39:55 -
@@ -37,7 +37,7 @@ struct renice_param {
 };
 
 int main(int, char **);
-static int renice(struct renice_param *, struct renice_param *);
+static int renice(struct renice_param *, struct renice_param *, int);
 __dead void usage(void);
 
 int
@@ -46,7 +46,7 @@ main(int argc, char **argv)
struct renice_param *params, *p;
struct passwd *pw;
int ch, type = PRIO_PROCESS;
-   int nflag = 0, pri = 0;
+   int nflag = 0, pri = 0, set_pri_flag = 0;
char *ep, *idstr;
const char *errstr;
long l;
@@ -61,7 +61,9 @@ main(int argc, char **argv)
 
/* Backwards compatibility: first arg may be priority. */
if (isdigit((unsigned char)argv[1][0]) ||
-   (argv[1][0] == '-'  isdigit((unsigned char)argv[1][1]))) {
+   (argv[1][0] == '-'  isdigit((unsigned char)argv[1][1])) ||
+   (argv[1][0] == '+'  isdigit((unsigned char)argv[1][1]))) {
+   set_pri_flag = 1;
argv[0] = -n;
argc++;
argv--;
@@ -79,6 +81,10 @@ main(int argc, char **argv)
idstr = optarg;
break;
case 'n':
+   if (set_pri_flag  nflag) {
+   warnx(-n not allowed when setting 
priority);
+   usage();
+   }
l = strtol(optarg, ep, 10);
if (*ep != '\0' || ep == optarg) {
warnx(invalid increment %s, optarg);
@@ -137,11 +143,11 @@ main(int argc, char **argv)
}
if (!nflag)
usage();
-   exit(renice(params, p));
+   exit(renice(params, p, set_pri_flag));
 }
 
 static int
-renice(struct renice_param *p, struct renice_param *end)
+renice(struct renice_param *p, struct renice_param *end, int set_priority_flag)
 {
int old, errors = 0;
 
@@ -153,6 +159,12 @@ renice(struct renice_param *p, struct re
errors++;
continue;
}
+   if (!set_priority_flag) {
+   /* increment instead of set priority */ 
+   p-pri = old + p-pri;
+   p-pri = p-pri  PRIO_MAX ? PRIO_MAX :
+   p-pri  PRIO_MIN ? PRIO_MIN : p-pri;
+   }
if (setpriority(p-type, p-id, p-pri) == -1) {
warn(setpriority: %d, p-id);
errors++;
@@ -167,7 +179,9 @@ renice(struct renice_param *p, struct re
 __dead void
 usage(void)
 {
-   fprintf(stderr, usage: renice -n increment [[-g] pgrp ...] 
+   fprintf(stderr, usage: renice priority [[-g] pgrp ...] 
+   [[-p] pid ...] [[-u] user ...]\n);
+   fprintf(stderr,renice -n increment [[-g] pgrp ...] 
[[-p] pid ...] [[-u] user ...]\n);
exit(1);
 }



Re: [PATCH] sync renice(8) with manpage and POSIX and other BSDs

2015-03-20 Thread Benjamin Baier
On Fri, 20 Mar 2015 10:35:07 -0600
Todd C. Miller todd.mil...@courtesan.com wrote:

 We do not typically document the historic usage.  However, in this
 case we might make an exception since the old and new syntax are
 semantically different (absolute vs. increment).
Up to you... The only thing i would push for, is
Index: renice.8
===
RCS file: /cvs/src/usr.bin/renice/renice.8,v
retrieving revision 1.23
diff -u -p -r1.23 renice.8
--- renice.823 May 2014 06:40:57 -  1.23
+++ renice.820 Mar 2015 18:33:24 -
@@ -131,7 +131,7 @@ utility is compliant with the
 specification,
 except the way in which processes are specified differs.
 .Pp
-The historical behavior of passing the increment as the first
+The historical behavior of passing the priority as the first
 argument is supported for backwards compatibility.
 .Sh HISTORY
 The

 I've adapted your diff as follows.
works for me. thanks.

  - todd
 
 Index: renice.c
 ===
 RCS file: /cvs/src/usr.bin/renice/renice.c,v
 retrieving revision 1.16
 diff -u -r1.16 renice.c
 --- renice.c  15 Nov 2013 22:20:04 -  1.16
 +++ renice.c  20 Mar 2015 16:29:05 -
 @@ -37,7 +37,7 @@
  };
  
  int main(int, char **);
 -static int renice(struct renice_param *, struct renice_param *);
 +static int renice(struct renice_param *, struct renice_param *, int);
  __dead void usage(void);
  
  int
 @@ -46,10 +46,9 @@
   struct renice_param *params, *p;
   struct passwd *pw;
   int ch, type = PRIO_PROCESS;
 - int nflag = 0, pri = 0;
 + int absolute = 0, nflag = 0, pri = 0;
   char *ep, *idstr;
   const char *errstr;
 - long l;
  
   if (argc  3)
   usage();
 @@ -61,10 +60,15 @@
  
   /* Backwards compatibility: first arg may be priority. */
   if (isdigit((unsigned char)argv[1][0]) ||
 - (argv[1][0] == '-'  isdigit((unsigned char)argv[1][1]))) {
 - argv[0] = -n;
 - argc++;
 - argv--;
 + ((argv[1][0] == '+' || argv[1][0] == '-') 
 + isdigit((unsigned char)argv[1][1]))) {
 + pri = (int)strtol(argv[1], ep, 10);
 + if (*ep != '\0' || ep == argv[1]) {
 + warnx(invalid priority %s, argv[1]);
 + usage();
 + }
 + absolute = 1;
 + optind = 2;
   }
  
   /*
 @@ -79,13 +83,15 @@
   idstr = optarg;
   break;
   case 'n':
 - l = strtol(optarg, ep, 10);
 + if (absolute) {
 + warnx(-n not allowed with historic 
 priority setting);
 + usage();
 + }
 + pri = (int)strtol(optarg, ep, 10);
   if (*ep != '\0' || ep == optarg) {
   warnx(invalid increment %s, optarg);
   usage();
   }
 - pri = l  PRIO_MAX ? PRIO_MAX :
 - l  PRIO_MIN ? PRIO_MIN : (int)l;
  
   /* Set priority for previous entries? */
   if (!nflag) {
 @@ -135,15 +141,15 @@
   }
   p++;
   }
 - if (!nflag)
 + if (!nflag  !absolute)
   usage();
 - exit(renice(params, p));
 + exit(renice(params, p, absolute));
  }
  
  static int
 -renice(struct renice_param *p, struct renice_param *end)
 +renice(struct renice_param *p, struct renice_param *end, int absolute)
  {
 - int old, errors = 0;
 + int new, old, errors = 0;
  
   for (; p  end; p++) {
   errno = 0;
 @@ -153,13 +159,17 @@
   errors++;
   continue;
   }
 - if (setpriority(p-type, p-id, p-pri) == -1) {
 + if (!absolute)
 + p-pri += old;
 + new = p-pri  PRIO_MAX ? PRIO_MAX :
 + p-pri  PRIO_MIN ? PRIO_MIN : p-pri;
 + if (setpriority(p-type, p-id, new) == -1) {
   warn(setpriority: %d, p-id);
   errors++;
   continue;
   }
   printf(%d: old priority %d, new priority %d\n,
 - p-id, old, p-pri);
 + p-id, old, new);
   }
   return (errors);
  }
 



[PATCH] double free in libkeynote

2015-02-04 Thread Benjamin Baier
don't free x after y = realloc(x, N) even if y != x
found by llvm/scan-build

Index: keynote.l
===
RCS file: /cvs/src/lib/libkeynote/keynote.l,v
retrieving revision 1.20
diff -u -p -U17 -r1.20 keynote.l
--- keynote.l   29 Nov 2013 19:00:51 -  1.20
+++ keynote.l   4 Feb 2015 11:00:30 -
@@ -272,37 +272,34 @@ keynote_lex_add(void *s, int type)
 p = (struct lex_list *) realloc(keynote_lex_list,
keynote_max_lex_list *
sizeof(struct lex_list));
 if (p == (struct lex_list *) NULL)
 {
switch (type)
{
case LEXTYPE_CHAR:
free(s);
break;
}
 
 keynote_max_lex_list /= 2;
keynote_errno = ERROR_MEMORY;
 return -1;
 }
 
-if (p != keynote_lex_list)
-   free(keynote_lex_list);
-
 keynote_lex_list = p;
 keynote_lex_list[i].lex_s = s;
 keynote_lex_list[i++].lex_type = type;
 keynote_lex_counter++;
 
 /* Zero out the rest */
 memset((keynote_lex_list[i]), 0,
   (keynote_max_lex_list - i) * sizeof(struct lex_list));
 
 return RESULT_TRUE;
 }
 
 /*
  * Remove string.
  */
 void
 keynote_lex_remove(void *s)



[PATCH] potentional double free in route6d(8)

2015-02-04 Thread Benjamin Baier
potentional double free in do-while-loop.
found by llvm/scan-build

Index: route6d.c
===
RCS file: /cvs/src/usr.sbin/route6d/route6d.c,v
retrieving revision 1.64
diff -u -p -r1.64 route6d.c
--- route6d.c   16 Jan 2015 06:40:20 -  1.64
+++ route6d.c   4 Feb 2015 13:43:50 -
@@ -2449,9 +2449,9 @@ krtread(int again)
mib[5] = 0; /* No flags */
do {
retry++;
+   free(buf);
+   buf = NULL;
errmsg = NULL;
-   if (buf)
-   free(buf);
if (sysctl(mib, 6, NULL, msize, NULL, 0)  0) {
errmsg = sysctl estimate;
continue;



Re: [PATCH]unused NULL check before calling free

2014-07-31 Thread Benjamin Baier

On 07/31/14 12:39, Fritjof Bornebusch wrote:

That's why there is no need, to use a condition like:
if(ptr == NULL)
errx(1, xfree: NULL pointer given as argument);


Yes, there is.
There is a big difference between free(NULL) and xfree(NULL).



[PATCH] sasyncd: malloc/memset = calloc

2014-07-04 Thread Benjamin Baier
i got a few easy ones left...

Index: net.c
===
RCS file: /cvs/src/usr.sbin/sasyncd/net.c,v
retrieving revision 1.20
diff -u -p -r1.20 net.c
--- net.c   11 Mar 2013 17:40:11 -  1.20
+++ net.c   11 Jun 2014 17:28:28 -
@@ -302,13 +302,12 @@ net_enqueue(struct syncpeer *p, struct m
if (p-socket  0)
return;
 
-   qm = (struct qmsg *)malloc(sizeof *qm);
+   qm = calloc(1, sizeof *qm);
if (!qm) {
-   log_err(net_enqueue: malloc());
+   log_err(net_enqueue: calloc());
return;
}
 
-   memset(qm, 0, sizeof *qm);
qm-msg = m;
m-refcnt++;



[PATCH] rtsold: malloc/memset = calloc

2014-07-04 Thread Benjamin Baier
Index: rtsold.c
===
RCS file: /cvs/src/usr.sbin/rtsold/rtsold.c,v
retrieving revision 1.50
diff -u -p -r1.50 rtsold.c
--- rtsold.c21 Oct 2013 08:46:07 -  1.50
+++ rtsold.c11 Jun 2014 17:28:11 -
@@ -324,12 +324,11 @@ ifconfig(char *ifname)
return(-1);
}
 
-   if ((ifinfo = malloc(sizeof(*ifinfo))) == NULL) {
+   if ((ifinfo = calloc(1, sizeof(*ifinfo))) == NULL) {
warnmsg(LOG_ERR, __func__, memory allocation failed);
free(sdl);
return(-1);
}
-   memset(ifinfo, 0, sizeof(*ifinfo));
ifinfo-sdl = sdl;
 
strncpy(ifinfo-ifname, ifname, sizeof(ifinfo-ifname));



[PATCH] rdist: malloc/memset = calloc

2014-07-04 Thread Benjamin Baier
Index: child.c
===
RCS file: /cvs/src/usr.bin/rdist/child.c,v
retrieving revision 1.16
diff -u -p -r1.16 child.c
--- child.c 18 Apr 2011 12:29:59 -  1.16
+++ child.c 9 Jun 2014 18:33:28 -
@@ -363,7 +363,6 @@ waitup(void)
CHILD *pc;
fd_set *rchildfdsp = NULL;
int rchildfdsn = 0;
-   size_t bytes;
 
debugmsg(DM_CALL, waitup() start\n);
 
@@ -379,11 +378,9 @@ waitup(void)
for (pc = childlist; pc; pc = pc-c_next)
if (pc-c_readfd  rchildfdsn)
rchildfdsn = pc-c_readfd;
-   bytes = howmany(rchildfdsn+1, NFDBITS) * sizeof(fd_mask);
-   if ((rchildfdsp = (fd_set *)malloc(bytes)) == NULL)
+   if ((rchildfdsp = calloc(howmany(rchildfdsn+1, NFDBITS), 
sizeof(fd_mask))) == NULL)
return;
 
-   memset(rchildfdsp, 0, bytes);
for (pc = childlist; pc; pc = pc-c_next)
if (pc-c_readfd  0) {
debugmsg(DM_MISC, waitup() select on %d (%s)\n,



[PATCH] rtadvd malloc/memset = calloc

2014-07-04 Thread Benjamin Baier
Index: config.c
===
RCS file: /cvs/src/usr.sbin/rtadvd/config.c,v
retrieving revision 1.40
diff -u -p -r1.40 config.c
--- config.c17 Oct 2013 16:27:48 -  1.40
+++ config.c11 Jun 2014 17:27:47 -
@@ -240,9 +240,8 @@ getconfig(intface)
continue;
 
/* allocate memory to store prefix information */
-   if ((pfx = malloc(sizeof(struct prefix))) == NULL)
-   fatal(malloc);
-   memset(pfx, 0, sizeof(*pfx));
+   if ((pfx = calloc(1, sizeof(*pfx))) == NULL)
+   fatal(calloc);
 
/* link into chain */
TAILQ_INSERT_TAIL(tmp-prefixes, pfx, entry);
@@ -568,9 +567,8 @@ get_prefix(struct rainfo *rai)
}
 
/* allocate memory to store prefix info. */
-   if ((pp = malloc(sizeof(*pp))) == NULL)
-   fatal(malloc);
-   memset(pp, 0, sizeof(*pp));
+   if ((pp = calloc(1, sizeof(*pp))) == NULL)
+   fatal(calloc);
 
/* set prefix, sweep bits outside of prefixlen */
pp-prefixlen = plen;
@@ -634,11 +632,10 @@ add_prefix(struct rainfo *rai, struct in
struct prefix *prefix;
u_char ntopbuf[INET6_ADDRSTRLEN];
 
-   if ((prefix = malloc(sizeof(*prefix))) == NULL) {
-   log_warn(malloc);
+   if ((prefix = calloc(1, sizeof(*prefix))) == NULL) {
+   log_warn(calloc);
return; /* XXX: error or exit? */
}
-   memset(prefix, 0, sizeof(*prefix));
prefix-prefix = ipr-ipr_prefix.sin6_addr;
prefix-prefixlen = ipr-ipr_plen;
prefix-validlifetime = ipr-ipr_vltime;
Index: rtadvd.c
===
RCS file: /cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.46
diff -u -p -r1.46 rtadvd.c
--- rtadvd.c15 May 2014 05:03:24 -  1.46
+++ rtadvd.c11 Jun 2014 17:27:48 -
@@ -249,15 +249,14 @@ main(argc, argv)
fatal(cannot drop privileges);
 
fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask);
-   if ((fdsetp = malloc(fdmasks)) == NULL) {
-   err(1, malloc);
+   if ((fdsetp = calloc(1, fdmasks)) == NULL) {
+   err(1, calloc);
/*NOTREACHED*/
}
if ((selectfdp = malloc(fdmasks)) == NULL) {
err(1, malloc);
/*NOTREACHED*/
}
-   memset(fdsetp, 0, fdmasks);
FD_SET(sock, fdsetp);
if (rtsock = 0)
FD_SET(rtsock, fdsetp);
Index: timer.c
===
RCS file: /cvs/src/usr.sbin/rtadvd/timer.c,v
retrieving revision 1.11
diff -u -p -r1.11 timer.c
--- timer.c 30 Apr 2013 12:30:40 -  1.11
+++ timer.c 11 Jun 2014 17:27:48 -
@@ -48,10 +48,8 @@ rtadvd_add_timer(void (*timeout)(void *)
 {
struct rtadvd_timer *newtimer;
 
-   if ((newtimer = malloc(sizeof(*newtimer))) == NULL)
-   fatal(malloc);
-
-   memset(newtimer, 0, sizeof(*newtimer));
+   if ((newtimer = calloc(1, sizeof(*newtimer))) == NULL)
+   fatal(calloc);
 
if (timeout == NULL)
fatalx(timeout function unspecified);



Re: [PATCH 8] aic7xxx: malloc/memset = calloc

2014-06-06 Thread Benjamin Baier
bump.
anybody care enought to commit?

On Sat, 31 May 2014 13:06:16 +0200
Benjamin Baier program...@netzbasis.de wrote:
Index: aicasm.c
===
RCS file: /cvs/src/sys/dev/microcode/aic7xxx/aicasm.c,v
retrieving revision 1.15
diff -u -p -r1.15 aicasm.c
--- aicasm.c5 Dec 2012 23:20:19 -   1.15
+++ aicasm.c31 May 2014 11:01:21 -
@@ -500,12 +500,10 @@ emit_patch(scope_t *scope, int patch)
/* No-Op patch */
return;
 
-   new_patch = (patch_t *)malloc(sizeof(*new_patch));
+   new_patch = calloc(1, sizeof(*new_patch));
 
if (new_patch == NULL)
-   stop(Could not malloc patch structure, EX_OSERR);
-
-   memset(new_patch, 0, sizeof(*new_patch));
+   stop(Could not calloc patch structure, EX_OSERR);
 
if (patch == 0) {
new_patch-patch_func = scope-func_num;
@@ -737,10 +735,9 @@ seq_alloc()
 {
struct instruction *new_instr;
 
-   new_instr = (struct instruction *)malloc(sizeof(struct instruction));
+   new_instr = calloc(1, sizeof(struct instruction));
if (new_instr == NULL)
-   stop(Unable to malloc instruction object, EX_SOFTWARE);
-   memset(new_instr, 0, sizeof(*new_instr));
+   stop(Unable to calloc instruction object, EX_SOFTWARE);
TAILQ_INSERT_TAIL(seq_program, new_instr, links);
new_instr-srcline = yylineno;
return new_instr;
@@ -751,10 +748,9 @@ cs_alloc()
 {
critical_section_t *new_cs;
 
-   new_cs= (critical_section_t *)malloc(sizeof(critical_section_t));
+   new_cs = calloc(1, sizeof(critical_section_t));
if (new_cs == NULL)
-   stop(Unable to malloc critical_section object, EX_SOFTWARE);
-   memset(new_cs, 0, sizeof(*new_cs));
+   stop(Unable to calloc critical_section object, EX_SOFTWARE);

TAILQ_INSERT_TAIL(cs_tailq, new_cs, links);
return new_cs;
@@ -765,10 +761,9 @@ scope_alloc()
 {
scope_t *new_scope;
 
-   new_scope = (scope_t *)malloc(sizeof(scope_t));
+   new_scope = calloc(1, sizeof(scope_t));
if (new_scope == NULL)
-   stop(Unable to malloc scope object, EX_SOFTWARE);
-   memset(new_scope, 0, sizeof(*new_scope));
+   stop(Unable to calloc scope object, EX_SOFTWARE);
TAILQ_INIT(new_scope-inner_scope);

if (SLIST_FIRST(scope_stack) != NULL) {
Index: aicasm_symbol.c
===
RCS file: /cvs/src/sys/dev/microcode/aic7xxx/aicasm_symbol.c,v
retrieving revision 1.11
diff -u -p -r1.11 aicasm_symbol.c
--- aicasm_symbol.c 5 Dec 2012 23:20:19 -   1.11
+++ aicasm_symbol.c 31 May 2014 11:01:21 -
@@ -68,12 +68,11 @@ symbol_create(char *name)
 {
symbol_t *new_symbol;
 
-   new_symbol = (symbol_t *)malloc(sizeof(symbol_t));
+   new_symbol = calloc(1, sizeof(symbol_t));
if (new_symbol == NULL) {
perror(Unable to create new symbol);
exit(EX_SOFTWARE);
}
-   memset(new_symbol, 0, sizeof(*new_symbol));
new_symbol-name = strdup(name);
if (new_symbol-name == NULL)
 stop(Unable to strdup symbol name, EX_SOFTWARE);



Re: [PATCH 10] inetd: malloc/memset = calloc

2014-06-06 Thread Benjamin Baier
bump.
anybody?

On Sat, 31 May 2014 16:40:35 +0200
Benjamin Baier program...@netzbasis.de wrote:
 While here also stop casting {m,c}alloc return value.
 
Index: inetd.c
===
RCS file: /cvs/src/usr.sbin/inetd/inetd.c,v
retrieving revision 1.137
diff -u -p -r1.137 inetd.c
--- inetd.c 23 Nov 2013 17:24:29 -  1.137
+++ inetd.c 31 May 2014 13:58:00 -
@@ -455,7 +455,7 @@ main(int argc, char *argv[])
if (readablen != allsockn) {
if (fdsrp)
free(fdsrp);
-   fdsrp = (fd_set *)calloc(allsockn, 1);
+   fdsrp = calloc(allsockn, 1);
if (fdsrp == NULL) {
syslog(LOG_ERR, Out of memory.);
exit(1);
@@ -1085,7 +1085,7 @@ enter(struct servtab *cp)
struct servtab *sep;
sigset_t omask;
 
-   sep = (struct servtab *)malloc(sizeof (*sep));
+   sep = malloc(sizeof (*sep));
if (sep == NULL) {
syslog(LOG_ERR, Out of memory.);
exit(1);
@@ -1180,13 +1180,11 @@ getconfigent(void)
char *arg, *cp, *hostdelim, *s;
int argc;
 
-   sep = (struct servtab *) malloc(sizeof(struct servtab));
+   sep = calloc(1, sizeof(struct servtab));
if (sep == NULL) {
-   syslog(LOG_ERR, malloc: %m);
+   syslog(LOG_ERR, calloc: %m);
exit(1);
}
-
-   memset(sep, 0, sizeof *sep);
 more:
freeconfig(sep);
 
@@ -1512,14 +1510,12 @@ dupconfig(struct servtab *sep)
struct servtab *newtab;
int argc;
 
-   newtab = (struct servtab *) malloc(sizeof(struct servtab));
+   newtab = calloc(1, sizeof(struct servtab));
 
if (newtab == NULL) {
-   syslog(LOG_ERR, malloc: %m);
+   syslog(LOG_ERR, calloc: %m);
exit(1);
}
-
-   memset(newtab, 0, sizeof(struct servtab));
 
newtab-se_service = sep-se_service ? newstr(sep-se_service) : NULL;
newtab-se_socktype = sep-se_socktype;



Re: [PATCH 9] installboot: malloc/memset = calloc

2014-06-06 Thread Benjamin Baier
bump.
anybody?

On Sat, 31 May 2014 20:29:42 +0200
Benjamin Baier program...@netzbasis.de wrote:
 On Sun, 1 Jun 2014 00:57:43 +1000
 Joel Sing j...@sing.id.au wrote:
  In this case I think readability wins. I do not believe that there is a lot 
  to 
  gain from overflow protection given the numbers used in these calculations 
  are very small (and many are already bounds checked in some form or other).
 
 Well, I had to ask. Here is option 2.
Index: bootstrap.c
===
RCS file: /cvs/src/usr.sbin/installboot/bootstrap.c,v
retrieving revision 1.3
diff -u -p -r1.3 bootstrap.c
--- bootstrap.c 28 Dec 2013 12:01:33 -  1.3
+++ bootstrap.c 31 May 2014 18:14:56 -
@@ -68,10 +68,9 @@ bootstrap(int devfd, char *dev, char *bo
fprintf(stderr, bootstrap is %zu bytes 
(%zu sectors @ %u bytes = %zu bytes)\n,
(ssize_t)sb.st_size, bootsec, dl.d_secsize, bootsize);
-   boot = malloc(bootsize);
+   boot = calloc(1, bootsize);
if (boot == NULL)
-   err(1, malloc);
-   memset(boot, 0, bootsize);
+   err(1, calloc);
if (read(fd, boot, bootsize) != (ssize_t)sb.st_size)
err(1, read);
close(fd);
Index: i386_softraid.c
===
RCS file: /cvs/src/usr.sbin/installboot/i386_softraid.c,v
retrieving revision 1.1
diff -u -p -r1.1 i386_softraid.c
--- i386_softraid.c 19 Jan 2014 02:58:50 -  1.1
+++ i386_softraid.c 31 May 2014 18:14:56 -
@@ -129,11 +129,10 @@ sr_install_bootldr(int devfd, char *dev)
inodeblk = nblocks - 1;
bootsize = nblocks * SR_FS_BLOCKSIZE;
 
-   p = malloc(bootsize);
+   p = calloc(1, bootsize);
if (p == NULL)
err(1, NULL);

-   memset(p, 0, bootsize);
fd = open(stage2, O_RDONLY, 0);
if (fd == -1)
err(1, NULL);
Index: sparc64_installboot.c
===
RCS file: /cvs/src/usr.sbin/installboot/sparc64_installboot.c,v
retrieving revision 1.1
diff -u -p -r1.1 sparc64_installboot.c
--- sparc64_installboot.c   19 Jan 2014 02:58:50 -  1.1
+++ sparc64_installboot.c   31 May 2014 18:14:56 -
@@ -68,10 +68,9 @@ md_loadboot(void)
if (blksize  SBSIZE - DEV_BSIZE)
errx(1, boot blocks too big (%zu  %d),
blksize, SBSIZE - DEV_BSIZE);
-   blkstore = malloc(blksize);
+   blkstore = calloc(1, blksize);
if (blkstore == NULL)
-   err(1, malloc);
-   memset(blkstore, 0, blksize);
+   err(1, calloc);
if (read(fd, blkstore, sb.st_size) != (ssize_t)sb.st_size)
err(1, read);
close(fd);



Re: exp2(3) bug?

2014-06-02 Thread Benjamin Baier
You might want to read up on floating point arithmetic. (rounding and 
representation)


On 06/02/14 05:13, Daniel Dickman wrote:

I hit this problem while working with the numpy 1.8.1 regress suite
which has some tests that are currently failing.

Here is a reduced test case of the logaddexp2 python function which
ends up calling exp2. Is this a bug in the openbsd exp2
implementation?

---8---
#include stdio.h
#include stdlib.h
#include math.h

int main(void) {
 double x;
 double y;

 // x = log2(5)
 x = 2.32192809489;
 // y = 2**(log2(5))
 y = exp2(x);

 printf(expected: 5.0\n);
 printf(actual:   %f\n, y);

---8---

on a linux/x86_64 machine:

# gcc -lm test.c  ./a.out
expected: 5.0
actual:   5.00

on an openbsd/i386 machine:

# gcc -lm test.c  ./a.out
expected: 5.0
actual:   4.994404





Re: exp2(3) bug?

2014-06-02 Thread Benjamin Baier
Ok i might have been quick to judge, because i don't really trust 
floating point arithmetic.


btw. exp2f works correct on i386.

On 06/02/14 10:17, Mark Kettenis wrote:

Date: Mon, 02 Jun 2014 09:34:20 +0200
From: Benjamin Baier program...@netzbasis.de

You might want to read up on floating point arithmetic. (rounding and
representation)


Well, the difference between 4.994404 and 5.0 is a bit large to blame
rounding and binary representation.  And other OpenBSD platforms
(amd64, sparc64, powerpc) return the expected result.  So I'd say that
there is a bug in the i386-specific implementation of exp2(3).


On 06/02/14 05:13, Daniel Dickman wrote:

I hit this problem while working with the numpy 1.8.1 regress suite
which has some tests that are currently failing.

Here is a reduced test case of the logaddexp2 python function which
ends up calling exp2. Is this a bug in the openbsd exp2
implementation?

---8---
#include stdio.h
#include stdlib.h
#include math.h

int main(void) {
  double x;
  double y;

  // x = log2(5)
  x = 2.32192809489;
  // y = 2**(log2(5))
  y = exp2(x);

  printf(expected: 5.0\n);
  printf(actual:   %f\n, y);

---8---

on a linux/x86_64 machine:

# gcc -lm test.c  ./a.out
expected: 5.0
actual:   5.00

on an openbsd/i386 machine:

# gcc -lm test.c  ./a.out
expected: 5.0
actual:   4.994404








[PATCH 8] aic7xxx: malloc/memset = calloc

2014-05-31 Thread Benjamin Baier
Index: aicasm.c
===
RCS file: /cvs/src/sys/dev/microcode/aic7xxx/aicasm.c,v
retrieving revision 1.15
diff -u -p -r1.15 aicasm.c
--- aicasm.c5 Dec 2012 23:20:19 -   1.15
+++ aicasm.c31 May 2014 11:01:21 -
@@ -500,12 +500,10 @@ emit_patch(scope_t *scope, int patch)
/* No-Op patch */
return;
 
-   new_patch = (patch_t *)malloc(sizeof(*new_patch));
+   new_patch = calloc(1, sizeof(*new_patch));
 
if (new_patch == NULL)
-   stop(Could not malloc patch structure, EX_OSERR);
-
-   memset(new_patch, 0, sizeof(*new_patch));
+   stop(Could not calloc patch structure, EX_OSERR);
 
if (patch == 0) {
new_patch-patch_func = scope-func_num;
@@ -737,10 +735,9 @@ seq_alloc()
 {
struct instruction *new_instr;
 
-   new_instr = (struct instruction *)malloc(sizeof(struct instruction));
+   new_instr = calloc(1, sizeof(struct instruction));
if (new_instr == NULL)
-   stop(Unable to malloc instruction object, EX_SOFTWARE);
-   memset(new_instr, 0, sizeof(*new_instr));
+   stop(Unable to calloc instruction object, EX_SOFTWARE);
TAILQ_INSERT_TAIL(seq_program, new_instr, links);
new_instr-srcline = yylineno;
return new_instr;
@@ -751,10 +748,9 @@ cs_alloc()
 {
critical_section_t *new_cs;
 
-   new_cs= (critical_section_t *)malloc(sizeof(critical_section_t));
+   new_cs = calloc(1, sizeof(critical_section_t));
if (new_cs == NULL)
-   stop(Unable to malloc critical_section object, EX_SOFTWARE);
-   memset(new_cs, 0, sizeof(*new_cs));
+   stop(Unable to calloc critical_section object, EX_SOFTWARE);

TAILQ_INSERT_TAIL(cs_tailq, new_cs, links);
return new_cs;
@@ -765,10 +761,9 @@ scope_alloc()
 {
scope_t *new_scope;
 
-   new_scope = (scope_t *)malloc(sizeof(scope_t));
+   new_scope = calloc(1, sizeof(scope_t));
if (new_scope == NULL)
-   stop(Unable to malloc scope object, EX_SOFTWARE);
-   memset(new_scope, 0, sizeof(*new_scope));
+   stop(Unable to calloc scope object, EX_SOFTWARE);
TAILQ_INIT(new_scope-inner_scope);

if (SLIST_FIRST(scope_stack) != NULL) {
Index: aicasm_symbol.c
===
RCS file: /cvs/src/sys/dev/microcode/aic7xxx/aicasm_symbol.c,v
retrieving revision 1.11
diff -u -p -r1.11 aicasm_symbol.c
--- aicasm_symbol.c 5 Dec 2012 23:20:19 -   1.11
+++ aicasm_symbol.c 31 May 2014 11:01:21 -
@@ -68,12 +68,11 @@ symbol_create(char *name)
 {
symbol_t *new_symbol;
 
-   new_symbol = (symbol_t *)malloc(sizeof(symbol_t));
+   new_symbol = calloc(1, sizeof(symbol_t));
if (new_symbol == NULL) {
perror(Unable to create new symbol);
exit(EX_SOFTWARE);
}
-   memset(new_symbol, 0, sizeof(*new_symbol));
new_symbol-name = strdup(name);
if (new_symbol-name == NULL)
 stop(Unable to strdup symbol name, EX_SOFTWARE);



[PATCH 9] installboot: malloc/memset = calloc

2014-05-31 Thread Benjamin Baier
This one splits up the malloc parameter, taking full potential from calloc, 
hurting readability a bit.
which one is preferred? more readable/maintainable or using the calloc overflow 
protection?

Index: bootstrap.c
===
RCS file: /cvs/src/usr.sbin/installboot/bootstrap.c,v
retrieving revision 1.3
diff -u -p -r1.3 bootstrap.c
--- bootstrap.c 28 Dec 2013 12:01:33 -  1.3
+++ bootstrap.c 31 May 2014 10:26:27 -
@@ -68,10 +68,9 @@ bootstrap(int devfd, char *dev, char *bo
fprintf(stderr, bootstrap is %zu bytes 
(%zu sectors @ %u bytes = %zu bytes)\n,
(ssize_t)sb.st_size, bootsec, dl.d_secsize, bootsize);
-   boot = malloc(bootsize);
+   boot = calloc(bootsec, dl.d_secsize);
if (boot == NULL)
-   err(1, malloc);
-   memset(boot, 0, bootsize);
+   err(1, calloc);
if (read(fd, boot, bootsize) != (ssize_t)sb.st_size)
err(1, read);
close(fd);
Index: i386_softraid.c
===
RCS file: /cvs/src/usr.sbin/installboot/i386_softraid.c,v
retrieving revision 1.1
diff -u -p -r1.1 i386_softraid.c
--- i386_softraid.c 19 Jan 2014 02:58:50 -  1.1
+++ i386_softraid.c 31 May 2014 10:26:27 -
@@ -129,11 +129,10 @@ sr_install_bootldr(int devfd, char *dev)
inodeblk = nblocks - 1;
bootsize = nblocks * SR_FS_BLOCKSIZE;
 
-   p = malloc(bootsize);
+   p = calloc(nblocks, SR_FS_BLOCKSIZE);
if (p == NULL)
err(1, NULL);

-   memset(p, 0, bootsize);
fd = open(stage2, O_RDONLY, 0);
if (fd == -1)
err(1, NULL);
Index: sparc64_installboot.c
===
RCS file: /cvs/src/usr.sbin/installboot/sparc64_installboot.c,v
retrieving revision 1.1
diff -u -p -r1.1 sparc64_installboot.c
--- sparc64_installboot.c   19 Jan 2014 02:58:50 -  1.1
+++ sparc64_installboot.c   31 May 2014 10:26:27 -
@@ -68,10 +68,9 @@ md_loadboot(void)
if (blksize  SBSIZE - DEV_BSIZE)
errx(1, boot blocks too big (%zu  %d),
blksize, SBSIZE - DEV_BSIZE);
-   blkstore = malloc(blksize);
+   blkstore = calloc(blocks, DEV_BSIZE);
if (blkstore == NULL)
-   err(1, malloc);
-   memset(blkstore, 0, blksize);
+   err(1, calloc);
if (read(fd, blkstore, sb.st_size) != (ssize_t)sb.st_size)
err(1, read);
close(fd);



[PATCH 10] inetd: malloc/memset = calloc

2014-05-31 Thread Benjamin Baier
While here also stop casting {m,c}alloc return value.

Index: inetd.c
===
RCS file: /cvs/src/usr.sbin/inetd/inetd.c,v
retrieving revision 1.137
diff -u -p -r1.137 inetd.c
--- inetd.c 23 Nov 2013 17:24:29 -  1.137
+++ inetd.c 31 May 2014 13:58:00 -
@@ -455,7 +455,7 @@ main(int argc, char *argv[])
if (readablen != allsockn) {
if (fdsrp)
free(fdsrp);
-   fdsrp = (fd_set *)calloc(allsockn, 1);
+   fdsrp = calloc(allsockn, 1);
if (fdsrp == NULL) {
syslog(LOG_ERR, Out of memory.);
exit(1);
@@ -1085,7 +1085,7 @@ enter(struct servtab *cp)
struct servtab *sep;
sigset_t omask;
 
-   sep = (struct servtab *)malloc(sizeof (*sep));
+   sep = malloc(sizeof (*sep));
if (sep == NULL) {
syslog(LOG_ERR, Out of memory.);
exit(1);
@@ -1180,13 +1180,11 @@ getconfigent(void)
char *arg, *cp, *hostdelim, *s;
int argc;
 
-   sep = (struct servtab *) malloc(sizeof(struct servtab));
+   sep = calloc(1, sizeof(struct servtab));
if (sep == NULL) {
-   syslog(LOG_ERR, malloc: %m);
+   syslog(LOG_ERR, calloc: %m);
exit(1);
}
-
-   memset(sep, 0, sizeof *sep);
 more:
freeconfig(sep);
 
@@ -1512,14 +1510,12 @@ dupconfig(struct servtab *sep)
struct servtab *newtab;
int argc;
 
-   newtab = (struct servtab *) malloc(sizeof(struct servtab));
+   newtab = calloc(1, sizeof(struct servtab));
 
if (newtab == NULL) {
-   syslog(LOG_ERR, malloc: %m);
+   syslog(LOG_ERR, calloc: %m);
exit(1);
}
-
-   memset(newtab, 0, sizeof(struct servtab));
 
newtab-se_service = sep-se_service ? newstr(sep-se_service) : NULL;
newtab-se_socktype = sep-se_socktype;



Re: [PATCH 9] installboot: malloc/memset = calloc

2014-05-31 Thread Benjamin Baier
On Sun, 1 Jun 2014 00:57:43 +1000
Joel Sing j...@sing.id.au wrote:
 In this case I think readability wins. I do not believe that there is a lot 
 to 
 gain from overflow protection given the numbers used in these calculations 
 are very small (and many are already bounds checked in some form or other).

Well, I had to ask. Here is option 2.

Index: bootstrap.c
===
RCS file: /cvs/src/usr.sbin/installboot/bootstrap.c,v
retrieving revision 1.3
diff -u -p -r1.3 bootstrap.c
--- bootstrap.c 28 Dec 2013 12:01:33 -  1.3
+++ bootstrap.c 31 May 2014 18:14:56 -
@@ -68,10 +68,9 @@ bootstrap(int devfd, char *dev, char *bo
fprintf(stderr, bootstrap is %zu bytes 
(%zu sectors @ %u bytes = %zu bytes)\n,
(ssize_t)sb.st_size, bootsec, dl.d_secsize, bootsize);
-   boot = malloc(bootsize);
+   boot = calloc(1, bootsize);
if (boot == NULL)
-   err(1, malloc);
-   memset(boot, 0, bootsize);
+   err(1, calloc);
if (read(fd, boot, bootsize) != (ssize_t)sb.st_size)
err(1, read);
close(fd);
Index: i386_softraid.c
===
RCS file: /cvs/src/usr.sbin/installboot/i386_softraid.c,v
retrieving revision 1.1
diff -u -p -r1.1 i386_softraid.c
--- i386_softraid.c 19 Jan 2014 02:58:50 -  1.1
+++ i386_softraid.c 31 May 2014 18:14:56 -
@@ -129,11 +129,10 @@ sr_install_bootldr(int devfd, char *dev)
inodeblk = nblocks - 1;
bootsize = nblocks * SR_FS_BLOCKSIZE;
 
-   p = malloc(bootsize);
+   p = calloc(1, bootsize);
if (p == NULL)
err(1, NULL);

-   memset(p, 0, bootsize);
fd = open(stage2, O_RDONLY, 0);
if (fd == -1)
err(1, NULL);
Index: sparc64_installboot.c
===
RCS file: /cvs/src/usr.sbin/installboot/sparc64_installboot.c,v
retrieving revision 1.1
diff -u -p -r1.1 sparc64_installboot.c
--- sparc64_installboot.c   19 Jan 2014 02:58:50 -  1.1
+++ sparc64_installboot.c   31 May 2014 18:14:56 -
@@ -68,10 +68,9 @@ md_loadboot(void)
if (blksize  SBSIZE - DEV_BSIZE)
errx(1, boot blocks too big (%zu  %d),
blksize, SBSIZE - DEV_BSIZE);
-   blkstore = malloc(blksize);
+   blkstore = calloc(1, blksize);
if (blkstore == NULL)
-   err(1, malloc);
-   memset(blkstore, 0, blksize);
+   err(1, calloc);
if (read(fd, blkstore, sb.st_size) != (ssize_t)sb.st_size)
err(1, read);
close(fd);



[PATCH 3] ld.so: malloc/memset = calloc

2014-05-26 Thread Benjamin Baier

Index: prebind_path.c
===
RCS file: /cvs/src/libexec/ld.so/ldconfig/prebind_path.c,v
retrieving revision 1.2
diff -u -p -r1.2 prebind_path.c
--- prebind_path.c  13 Nov 2013 05:41:43 -  1.2
+++ prebind_path.c  25 May 2014 08:19:14 -
@@ -24,10 +24,7 @@
 void *
 _dl_malloc(size_t need)
 {
-   void *ret = malloc(need);
-   if (ret != NULL)
-   memset(ret, 0, need);
-   return (ret);
+   return calloc(1, need);
 }
 
 void



[PATCH 5] regress videotest: malloc/memset = calloc

2014-05-26 Thread Benjamin Baier

Index: videotest.c
===
RCS file: /cvs/src/regress/sys/dev/video/videotest.c,v
retrieving revision 1.3
diff -u -p -r1.3 videotest.c
--- videotest.c 22 Jul 2010 11:58:03 -  1.3
+++ videotest.c 25 May 2014 08:30:04 -
@@ -356,16 +356,14 @@ test_capture(char *dev_name, char *dev_f
}
 
buf_size = fmt.fmt.pix.sizeimage;
-   buf = malloc(buf_size);
+   buf = calloc(1, buf_size);
if (buf == NULL)
goto error;
-   memset(buf, 0, buf_size);
 
img_size = fmt.fmt.pix.sizeimage + 1024;
-   img = malloc(img_size);
+   img = calloc(1, img_size);
if (img == NULL)
goto error;
-   memset(img, 0, img_size);
 
/* get frame */
if (access == ACCESS_READ)



Re: [PATCH 3] ld.so: malloc/memset = calloc

2014-05-26 Thread Benjamin Baier
Those are just suggestions... 
I'm going trough my list so in the future a simple NO and I'll stop tracking 
the patch and back off.

On Mon, 26 May 2014 12:57:10 -0600
Theo de Raadt dera...@cvs.openbsd.org wrote:

 no no, please stay out of ld.so and subdirectories.
 
 I'm working on these kinds of issues in there already, and I don't
 want any collisions.
 
  Index: prebind_path.c
  ===
  RCS file: /cvs/src/libexec/ld.so/ldconfig/prebind_path.c,v
  retrieving revision 1.2
  diff -u -p -r1.2 prebind_path.c
  --- prebind_path.c  13 Nov 2013 05:41:43 -  1.2
  +++ prebind_path.c  25 May 2014 08:19:14 -
  @@ -24,10 +24,7 @@
   void *
   _dl_malloc(size_t need)
   {
  -   void *ret = malloc(need);
  -   if (ret != NULL)
  -   memset(ret, 0, need);
  -   return (ret);
  +   return calloc(1, need);
   }
   
   void
  
 



[PATCH 4] config: malloc/memset = calloc

2014-05-26 Thread Benjamin Baier

Index: util.c
===
RCS file: /cvs/src/usr.sbin/config/util.c,v
retrieving revision 1.14
diff -u -p -r1.14 util.c
--- util.c  18 May 2014 09:29:54 -  1.14
+++ util.c  25 May 2014 11:38:40 -
@@ -62,9 +62,8 @@ emalloc(size_t size)
 {
void *p;
 
-   if ((p = malloc(size)) == NULL)
+   if ((p = calloc(1, size)) == NULL)
nomem();
-   memset(p, 0, size);
return (p);
 }



[PATCH 6] rcs: xmalloc/memset = xcalloc

2014-05-26 Thread Benjamin Baier
Yes, there is a xcalloc in xmalloc.h/.c.

Index: rcsutil.c
===
RCS file: /cvs/src/usr.bin/rcs/rcsutil.c,v
retrieving revision 1.39
diff -u -p -r1.39 rcsutil.c
--- rcsutil.c   16 Apr 2013 20:24:45 -  1.39
+++ rcsutil.c   25 May 2014 10:56:54 -
@@ -479,12 +479,10 @@ rcs_splitlines(u_char *data, size_t len)
struct rcs_line *lp;
size_t i, tlen;
 
-   lines = xmalloc(sizeof(*lines));
-   memset(lines, 0, sizeof(*lines));
+   lines = xcalloc(1, sizeof(*lines));
TAILQ_INIT((lines-l_lines));
 
-   lp = xmalloc(sizeof(*lp));
-   memset(lp, 0, sizeof(*lp));
+   lp = xcalloc(1, sizeof(*lp));
TAILQ_INSERT_TAIL((lines-l_lines), lp, l_list);



[PATCH 7] npppd: malloc/memset = calloc

2014-05-26 Thread Benjamin Baier
and a big one.

Index: common/bytebuf.c
===
RCS file: /cvs/src/usr.sbin/npppd/common/bytebuf.c,v
retrieving revision 1.5
diff -u -p -r1.5 bytebuf.c
--- common/bytebuf.c8 May 2012 13:15:11 -   1.5
+++ common/bytebuf.c26 May 2014 20:16:32 -
@@ -96,15 +96,12 @@ bytebuffer_create(size_t capacity)
 {
bytebuffer *_this = NULL;
 
-   if ((_this = malloc(sizeof(bytebuffer))) == NULL)
+   if ((_this = calloc(1, sizeof(bytebuffer))) == NULL)
return NULL;
 
-   memset(_this, 0, sizeof(bytebuffer));
-
if (capacity  0) {
-   if ((_this-data = malloc(capacity)) == NULL)
+   if ((_this-data = calloc(1, capacity)) == NULL)
goto fail;
-   memset(_this-data, 0, capacity);
_this-capacity = capacity;
} else
_this-capacity = 0;

Index: npppd/npppd_auth.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd_auth.c,v
retrieving revision 1.13
diff -u -p -r1.13 npppd_auth.c
--- npppd/npppd_auth.c  22 Mar 2014 04:23:17 -  1.13
+++ npppd/npppd_auth.c  26 May 2014 20:16:32 -
@@ -73,8 +73,7 @@ npppd_auth_create(int auth_type, const c
 
switch (auth_type) {
case NPPPD_AUTH_TYPE_LOCAL:
-   if ((base = malloc(sizeof(npppd_auth_local))) != NULL) {
-   memset(base, 0, sizeof(npppd_auth_local));
+   if ((base = calloc(1, sizeof(npppd_auth_local))) != NULL) {
base-type = NPPPD_AUTH_TYPE_LOCAL;
base-strip_nt_domain = 1;
base-strip_atmark_realm = 0;
@@ -87,9 +86,8 @@ npppd_auth_create(int auth_type, const c
 
 #ifdef USE_NPPPD_RADIUS
case NPPPD_AUTH_TYPE_RADIUS:
-   if ((base = malloc(sizeof(npppd_auth_radius))) != NULL) {
+   if ((base = calloc(1, sizeof(npppd_auth_radius))) != NULL) {
npppd_auth_radius *_this = (npppd_auth_radius *)base;
-   memset(base, 0, sizeof(npppd_auth_radius));
base-type = NPPPD_AUTH_TYPE_RADIUS;
base-strip_nt_domain = 0;
strlcpy(base-name, name, sizeof(base-name));

Index: npppd/npppd_ctl.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd_ctl.c,v
retrieving revision 1.11
diff -u -p -r1.11 npppd_ctl.c
--- npppd/npppd_ctl.c   22 Mar 2014 04:30:31 -  1.11
+++ npppd/npppd_ctl.c   26 May 2014 20:16:32 -
@@ -71,9 +71,8 @@ npppd_ctl_create(npppd *_this)
 {
struct npppd_ctl *ctl;
 
-   if ((ctl = malloc(sizeof(struct npppd_ctl))) == NULL)
+   if ((ctl = calloc(1, sizeof(struct npppd_ctl))) == NULL)
return (NULL);
-   memset(ctl, 0, sizeof(struct npppd_ctl));
ctl-npppd = _this;
TAILQ_INIT(ctl-stopped_ppps);
 
Index: npppd/ppp.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/ppp.c,v
retrieving revision 1.20
diff -u -p -r1.20 ppp.c
--- npppd/ppp.c 22 Mar 2014 04:32:39 -  1.20
+++ npppd/ppp.c 26 May 2014 20:16:32 -
@@ -109,11 +109,10 @@ ppp_create()
 {
npppd_ppp *_this;
 
-   if ((_this = malloc(sizeof(npppd_ppp))) == NULL) {
-   log_printf(LOG_ERR, malloc() failed in %s(): %m, __func__ );
+   if ((_this = calloc(1, sizeof(npppd_ppp))) == NULL) {
+   log_printf(LOG_ERR, calloc() failed in %s(): %m, __func__ );
return NULL;
}
-   memset(_this, 0, sizeof(npppd_ppp));
 
_this-snp.snp_family = AF_INET;
_this-snp.snp_len = sizeof(_this-snp);

Index: npppd/radius_req.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/radius_req.c,v
retrieving revision 1.7
diff -u -p -r1.7 radius_req.c
--- npppd/radius_req.c  22 Mar 2014 04:25:00 -  1.7
+++ npppd/radius_req.c  26 May 2014 20:16:33 -
@@ -275,11 +275,10 @@ radius_prepare(radius_req_setting *setti
 
if (setting-server[setting-curr_server].enabled == 0)
return 1;
-   if ((lap = malloc(sizeof(struct overlapped))) == NULL) {
-   log_printf(LOG_ERR, malloc() failed in %s: %m, __func__);
+   if ((lap = calloc(1, sizeof(struct overlapped))) == NULL) {
+   log_printf(LOG_ERR, calloc() failed in %s: %m, __func__);
goto fail;
}
-   memset(lap, 0, sizeof(struct overlapped));
lap-context = context;
lap-response_fn = response_fn;
lap-socket = -1;
@@ -534,13 +533,7 @@ fail:
 radius_req_setting *
 radius_req_setting_create(void)
 {
-   radius_req_setting *setting;
-
-   if ((setting = malloc(sizeof(radius_req_setting))) == NULL)
-   return NULL;
-   

[PATCH SET] malloc + memset = calloc

2014-05-25 Thread Benjamin Baier

Hi tech@

I'm just geting into the OpenBSD source code, and what better way to 
learn than with real work...


Some malloc/memset to calloc changes. More to come if this kind of work 
is appreciated.


Index: answer.c
===
RCS file: /cvs/src/games/hunt/huntd/answer.c,v
retrieving revision 1.12
diff -u -p -r1.12 answer.c
--- answer.c23 Mar 2014 02:42:47 -  1.12
+++ answer.c24 May 2014 19:43:20 -
@@ -77,13 +77,12 @@ answer_first()
}

/* Remember this spawning connection: */
-   sp = (struct spawn *)malloc(sizeof *sp);
+   sp = (struct spawn *)calloc(1, sizeof *sp);
if (sp == NULL) {
logit(LOG_ERR, malloc);
close(newsock);
return;
}
-   memset(sp, '\0', sizeof *sp);

/* Keep the calling machine's source addr for ident purposes: */
memcpy(sp-source, sockstruct, sizeof sp-source);

Index: bt_open.c
===
RCS file: /cvs/src/lib/libc/db/btree/bt_open.c,v
retrieving revision 1.16
diff -u -p -r1.16 bt_open.c
--- bt_open.c   30 Sep 2013 12:02:31 -  1.16
+++ bt_open.c   24 May 2014 20:05:02 -
@@ -150,9 +150,8 @@ __bt_open(const char *fname, int flags,
goto einval;

/* Allocate and initialize DB and BTREE structures. */
-   if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL)
+   if ((t = (BTREE *)calloc(1, sizeof(BTREE))) == NULL)
goto err;
-   memset(t, 0, sizeof(BTREE));
t-bt_fd = -1;   /* Don't close unopened fd on 
error. */
t-bt_lorder = b.lorder;
t-bt_order = NOT;

Index: auth_subr.c
===
RCS file: /cvs/src/lib/libc/gen/auth_subr.c,v
retrieving revision 1.39
diff -u -p -r1.39 auth_subr.c
--- auth_subr.c 24 Nov 2013 23:51:29 -  1.39
+++ auth_subr.c 24 May 2014 20:14:00 -
@@ -167,8 +167,7 @@ auth_open(void)
 {
auth_session_t *as;

-   if ((as = malloc(sizeof(auth_session_t))) != NULL) {
-   memset(as, 0, sizeof(*as));
+   if ((as = calloc(1, sizeof(auth_session_t))) != NULL) {
as-service = defservice;
as-fd = -1;
}

Index: fts.c
===
RCS file: /cvs/src/lib/libc/gen/fts.c,v
retrieving revision 1.45
diff -u -p -r1.45 fts.c
--- fts.c   30 Sep 2013 12:02:33 -  1.45
+++ fts.c   24 May 2014 20:17:02 -
@@ -906,10 +906,9 @@ fts_alloc(FTS *sp, char *name, size_t na
len = sizeof(FTSENT) + namelen;
if (!ISSET(FTS_NOSTAT))
len += sizeof(struct stat) + ALIGNBYTES;
-   if ((p = malloc(len)) == NULL)
+   if ((p = calloc(1, len)) == NULL)
return (NULL);

-   memset(p, 0, len);
p-fts_path = sp-fts_path;
p-fts_namelen = namelen;
p-fts_instr = FTS_NOINSTR;

Index: rune.c
===
RCS file: /cvs/src/lib/libc/locale/rune.c,v
retrieving revision 1.3
diff -u -p -r1.3 rune.c
--- rune.c  5 Dec 2012 23:20:00 -   1.3
+++ rune.c  24 May 2014 20:22:49 -
@@ -230,9 +230,8 @@ _Read_RuneMagi(FILE *fp)
ntohl(frl.frl_maplower_ext.frr_nranges) * sizeof(_RuneEntry) +
ntohl(frl.frl_mapupper_ext.frr_nranges) * sizeof(_RuneEntry);

-   if ((hostdata = malloc(hostdatalen)) == NULL)
+   if ((hostdata = calloc(1, hostdatalen)) == NULL)
return NULL;
-   memset(hostdata, 0, hostdatalen);
lastp = hostdata + hostdatalen;

rl = (_RuneLocale *)hostdata;

Index: yp_bind.c
===
RCS file: /cvs/src/lib/libc/yp/yp_bind.c,v
retrieving revision 1.19
diff -u -p -r1.19 yp_bind.c
--- yp_bind.c   30 Sep 2013 12:02:36 -  1.19
+++ yp_bind.c   24 May 2014 20:27:27 -
@@ -97,9 +97,8 @@ _yp_dobind(const char *dom, struct dom_b
if (strcmp(dom, ysd-dom_domain) == 0)
break;
if (ysd == NULL) {
-   if ((ysd = malloc(sizeof *ysd)) == NULL)
+   if ((ysd = calloc(1, sizeof *ysd)) == NULL)
return YPERR_RESRC;
-   (void)memset(ysd, 0, sizeof *ysd);
ysd-dom_socket = -1;
ysd-dom_vers = 0;
new = 1;

Index: fts1.c
===
RCS file: /cvs/src/lib/libsqlite3/ext/fts1/fts1.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 fts1.c
--- fts1.c  21 Sep 2013 17:29:18 -  1.1.1.2
+++ fts1.c  24 May 2014 20:56:05 -
@@ -1945,9 +1945,8 @@ static int constructVtab(
   const sqlite3_tokenizer_module *m = NULL;
   char *schema;

-  v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab));
+  v = 

Re: [PATCH SET] malloc + memset = calloc

2014-05-25 Thread Benjamin Baier
Now with correct tabs... sorry.

Hi tech@

I'm just geting into the OpenBSD source code, and what better way to 
learn than with real work...

Some malloc/memset to calloc changes. More to come if this kind of work 
is appreciated.

Index: answer.c
===
RCS file: /cvs/src/games/hunt/huntd/answer.c,v
retrieving revision 1.12
diff -u -p -r1.12 answer.c
--- answer.c23 Mar 2014 02:42:47 -  1.12
+++ answer.c24 May 2014 19:43:20 -
@@ -77,13 +77,12 @@ answer_first()
}
 
/* Remember this spawning connection: */
-   sp = (struct spawn *)malloc(sizeof *sp);
+   sp = (struct spawn *)calloc(1, sizeof *sp);
if (sp == NULL) {
logit(LOG_ERR, malloc);
close(newsock);
return;
}
-   memset(sp, '\0', sizeof *sp);
 
/* Keep the calling machine's source addr for ident purposes: */
memcpy(sp-source, sockstruct, sizeof sp-source);

Index: bt_open.c
===
RCS file: /cvs/src/lib/libc/db/btree/bt_open.c,v
retrieving revision 1.16
diff -u -p -r1.16 bt_open.c
--- bt_open.c   30 Sep 2013 12:02:31 -  1.16
+++ bt_open.c   24 May 2014 20:05:02 -
@@ -150,9 +150,8 @@ __bt_open(const char *fname, int flags, 
goto einval;
 
/* Allocate and initialize DB and BTREE structures. */
-   if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL)
+   if ((t = (BTREE *)calloc(1, sizeof(BTREE))) == NULL)
goto err;
-   memset(t, 0, sizeof(BTREE));
t-bt_fd = -1;  /* Don't close unopened fd on error. */
t-bt_lorder = b.lorder;
t-bt_order = NOT;

 
Index: auth_subr.c
===
RCS file: /cvs/src/lib/libc/gen/auth_subr.c,v
retrieving revision 1.39
diff -u -p -r1.39 auth_subr.c
--- auth_subr.c 24 Nov 2013 23:51:29 -  1.39
+++ auth_subr.c 24 May 2014 20:14:00 -
@@ -167,8 +167,7 @@ auth_open(void)
 {
auth_session_t *as;
 
-   if ((as = malloc(sizeof(auth_session_t))) != NULL) {
-   memset(as, 0, sizeof(*as));
+   if ((as = calloc(1, sizeof(auth_session_t))) != NULL) {
as-service = defservice;
as-fd = -1;
}

Index: fts.c
===
RCS file: /cvs/src/lib/libc/gen/fts.c,v
retrieving revision 1.45
diff -u -p -r1.45 fts.c
--- fts.c   30 Sep 2013 12:02:33 -  1.45
+++ fts.c   24 May 2014 20:17:02 -
@@ -906,10 +906,9 @@ fts_alloc(FTS *sp, char *name, size_t na
len = sizeof(FTSENT) + namelen;
if (!ISSET(FTS_NOSTAT))
len += sizeof(struct stat) + ALIGNBYTES;
-   if ((p = malloc(len)) == NULL)
+   if ((p = calloc(1, len)) == NULL)
return (NULL);
 
-   memset(p, 0, len);
p-fts_path = sp-fts_path;
p-fts_namelen = namelen;
p-fts_instr = FTS_NOINSTR;

Index: rune.c
===
RCS file: /cvs/src/lib/libc/locale/rune.c,v
retrieving revision 1.3
diff -u -p -r1.3 rune.c
--- rune.c  5 Dec 2012 23:20:00 -   1.3
+++ rune.c  24 May 2014 20:22:49 -
@@ -230,9 +230,8 @@ _Read_RuneMagi(FILE *fp)
ntohl(frl.frl_maplower_ext.frr_nranges) * sizeof(_RuneEntry) +
ntohl(frl.frl_mapupper_ext.frr_nranges) * sizeof(_RuneEntry);
 
-   if ((hostdata = malloc(hostdatalen)) == NULL)
+   if ((hostdata = calloc(1, hostdatalen)) == NULL)
return NULL;
-   memset(hostdata, 0, hostdatalen);
lastp = hostdata + hostdatalen;
 
rl = (_RuneLocale *)hostdata;

Index: yp_bind.c
===
RCS file: /cvs/src/lib/libc/yp/yp_bind.c,v
retrieving revision 1.19
diff -u -p -r1.19 yp_bind.c
--- yp_bind.c   30 Sep 2013 12:02:36 -  1.19
+++ yp_bind.c   24 May 2014 20:27:27 -
@@ -97,9 +97,8 @@ _yp_dobind(const char *dom, struct dom_b
if (strcmp(dom, ysd-dom_domain) == 0)
break;
if (ysd == NULL) {
-   if ((ysd = malloc(sizeof *ysd)) == NULL)
+   if ((ysd = calloc(1, sizeof *ysd)) == NULL)
return YPERR_RESRC;
-   (void)memset(ysd, 0, sizeof *ysd);
ysd-dom_socket = -1;
ysd-dom_vers = 0;
new = 1;

Index: fts1.c
===
RCS file: /cvs/src/lib/libsqlite3/ext/fts1/fts1.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 fts1.c
--- fts1.c  21 Sep 2013 17:29:18 -  1.1.1.2
+++ fts1.c  24 May 2014 20:56:05 -
@@ -1945,9 +1945,8 @@ static int constructVtab(
   const sqlite3_tokenizer_module *m = NULL;
   char *schema;
 
-  v = (fulltext_vtab *) 

Re: [PATCH SET] malloc + memset = calloc

2014-05-25 Thread Benjamin Baier
On Sun, 25 May 2014 10:08:06 +0100 Stuart Henderson st...@openbsd.org wrote:
 There are a couple like this:
 
  -   pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
  +   pre_comp = calloc(num_points * 17 * 3, sizeof(felem));
 
 Wouldn't they be better like this?
 
   pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
 

Yes indeed. But once you(I) start worrying about overflow, it's opening 
pandoras box, and I'm not quite there yet.
i.e. what do you make of this?
tmp_felems = malloc((num_points * 17 + 1) * sizeof(felem));

Nevertheless...

Index: ecp_nistp224.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp224.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp224.c
--- ecp_nistp224.c  15 May 2014 11:25:59 -  1.7
+++ ecp_nistp224.c  25 May 2014 09:41:35 -
@@ -1435,8 +1435,8 @@ ec_GFp_nistp224_points_mul(const EC_GROU
 */
mixed = 1;
}
-   secrets = malloc(num_points * sizeof(felem_bytearray));
-   pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+   secrets = calloc(num_points, sizeof(felem_bytearray));
+   pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) * 
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed  
(tmp_felems == NULL))) {
@@ -1448,8 +1448,6 @@ ec_GFp_nistp224_points_mul(const EC_GROU
 * infinity, i.e., they contribute nothing to the linear
 * combination
 */
-   memset(secrets, 0, num_points * sizeof(felem_bytearray));
-   memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i  num_points; ++i) {
if (i == num)
/* the generator */
Index: ecp_nistp256.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp256.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp256.c
--- ecp_nistp256.c  15 May 2014 11:25:59 -  1.7
+++ ecp_nistp256.c  25 May 2014 09:43:43 -
@@ -1985,8 +1985,8 @@ ec_GFp_nistp256_points_mul(const EC_GROU
 */
mixed = 1;
}
-   secrets = malloc(num_points * sizeof(felem_bytearray));
-   pre_comp = malloc(num_points * 17 * 3 * sizeof(smallfelem));
+   secrets = calloc(num_points, sizeof(felem_bytearray));
+   pre_comp = calloc(num_points, 17 * 3 * sizeof(smallfelem));
if (mixed)
tmp_smallfelems = malloc((num_points * 17 + 1) * 
sizeof(smallfelem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed  
(tmp_smallfelems == NULL))) {
@@ -1998,8 +1998,6 @@ ec_GFp_nistp256_points_mul(const EC_GROU
 * infinity, i.e., they contribute nothing to the linear
 * combination
 */
-   memset(secrets, 0, num_points * sizeof(felem_bytearray));
-   memset(pre_comp, 0, num_points * 17 * 3 * sizeof(smallfelem));
for (i = 0; i  num_points; ++i) {
if (i == num)
/*
Index: ecp_nistp521.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp521.c,v
retrieving revision 1.8
diff -u -p -r1.8 ecp_nistp521.c
--- ecp_nistp521.c  15 May 2014 11:25:59 -  1.8
+++ ecp_nistp521.c  25 May 2014 09:45:06 -
@@ -1872,8 +1872,8 @@ ec_GFp_nistp521_points_mul(const EC_GROU
 */
mixed = 1;
}
-   secrets = malloc(num_points * sizeof(felem_bytearray));
-   pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+   secrets = calloc(num_points, sizeof(felem_bytearray));
+   pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) * 
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed  
(tmp_felems == NULL))) {
@@ -1885,8 +1885,6 @@ ec_GFp_nistp521_points_mul(const EC_GROU
 * infinity, i.e., they contribute nothing to the linear
 * combination
 */
-   memset(secrets, 0, num_points * sizeof(felem_bytearray));
-   memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i  num_points; ++i) {
if (i == num)
/*



[PATCH SET] libssl: malloc/memset = calloc

2014-05-25 Thread Benjamin Baier

Hi tech@
patch set for libssl

Index: bn_blind.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/bn/bn_blind.c,v
retrieving revision 1.9
diff -u -p -r1.9 bn_blind.c
--- bn_blind.c  8 May 2014 13:20:49 -   1.9
+++ bn_blind.c  24 May 2014 21:09:40 -
@@ -139,11 +139,10 @@ BN_BLINDING_new(const BIGNUM *A, const B
 
bn_check_top(mod);
 
-   if ((ret = (BN_BLINDING *)malloc(sizeof(BN_BLINDING))) == NULL) {
+   if ((ret = calloc(1, sizeof(BN_BLINDING))) == NULL) {
BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
-   memset(ret, 0, sizeof(BN_BLINDING));
if (A != NULL) {
if ((ret-A = BN_dup(A))  == NULL)
goto err;

Index: comp_lib.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/comp/comp_lib.c,v
retrieving revision 1.5
diff -u -p -r1.5 comp_lib.c
--- comp_lib.c  26 Apr 2014 13:04:24 -  1.5
+++ comp_lib.c  24 May 2014 21:12:44 -
@@ -9,11 +9,10 @@ COMP_CTX_new(COMP_METHOD *meth)
 {
COMP_CTX *ret;
 
-   if ((ret = (COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL) {
+   if ((ret = calloc(1, sizeof(COMP_CTX))) == NULL) {
/*  */
return (NULL);
}
-   memset(ret, 0, sizeof(COMP_CTX));
ret-meth = meth;
if ((ret-meth-init != NULL)  !ret-meth-init(ret)) {
free(ret);

Index: pmeth_lib.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/evp/pmeth_lib.c,v
retrieving revision 1.3
diff -u -p -r1.3 pmeth_lib.c
--- pmeth_lib.c 7 May 2014 17:42:51 -   1.3
+++ pmeth_lib.c 24 May 2014 21:30:17 -
@@ -196,11 +196,9 @@ EVP_PKEY_meth_new(int id, int flags)
 {
EVP_PKEY_METHOD *pmeth;
 
-   pmeth = malloc(sizeof(EVP_PKEY_METHOD));
+   pmeth = calloc(1, sizeof(EVP_PKEY_METHOD));
if (!pmeth)
return NULL;
-
-   memset(pmeth, 0, sizeof(EVP_PKEY_METHOD));
 
pmeth-pkey_id = id;
pmeth-flags = flags | EVP_PKEY_FLAG_DYNAMIC;

Index: bio_ber.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/pkcs7/bio_ber.c,v
retrieving revision 1.9
diff -u -p -r1.9 bio_ber.c
--- bio_ber.c   27 Apr 2014 20:26:49 -  1.9
+++ bio_ber.c   24 May 2014 21:32:22 -
@@ -126,10 +126,8 @@ static int ber_new(BIO *bi)
{
BIO_BER_CTX *ctx;
 
-   ctx=(BIO_BER_CTX *)malloc(sizeof(BIO_BER_CTX));
+   ctx=calloc(1, sizeof(BIO_BER_CTX));
if (ctx == NULL) return(0);
-
-   memset((char *)ctx,0,sizeof(BIO_BER_CTX));
 
bi-init=0;
bi-ptr=(char *)ctx;

Index: ecp_nistp224.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp224.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp224.c
--- ecp_nistp224.c  15 May 2014 11:25:59 -  1.7
+++ ecp_nistp224.c  25 May 2014 09:41:35 -
@@ -1435,8 +1435,8 @@ ec_GFp_nistp224_points_mul(const EC_GROU
 */
mixed = 1;
}
-   secrets = malloc(num_points * sizeof(felem_bytearray));
-   pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+   secrets = calloc(num_points, sizeof(felem_bytearray));
+   pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) * 
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed  
(tmp_felems == NULL))) {
@@ -1448,8 +1448,6 @@ ec_GFp_nistp224_points_mul(const EC_GROU
 * infinity, i.e., they contribute nothing to the linear
 * combination
 */
-   memset(secrets, 0, num_points * sizeof(felem_bytearray));
-   memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i  num_points; ++i) {
if (i == num)
/* the generator */

Index: ecp_nistp256.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp256.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp256.c
--- ecp_nistp256.c  15 May 2014 11:25:59 -  1.7
+++ ecp_nistp256.c  25 May 2014 09:43:43 -
@@ -1985,8 +1985,8 @@ ec_GFp_nistp256_points_mul(const EC_GROU
 */
mixed = 1;
}
-   secrets = malloc(num_points * sizeof(felem_bytearray));
-   pre_comp = malloc(num_points * 17 * 3 * sizeof(smallfelem));
+   secrets = calloc(num_points, sizeof(felem_bytearray));
+   pre_comp = 

[PATCH 2] libssl: malloc/memset = calloc

2014-05-25 Thread Benjamin Baier

This shortens the function quite a bit.

Index: str_lib.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/store/str_lib.c,v
retrieving revision 1.4
diff -u -p -r1.4 str_lib.c
--- str_lib.c   17 Apr 2014 21:32:37 -  1.4
+++ str_lib.c   25 May 2014 07:49:06 -
@@ -1185,10 +1185,9 @@ int STORE_delete_arbitrary(STORE *s, OPE
 
 STORE_OBJECT *STORE_OBJECT_new(void)
{
-   STORE_OBJECT *object = malloc(sizeof(STORE_OBJECT));
-   if (object) memset(object, 0, sizeof(STORE_OBJECT));
-   return object;
+   return (STORE_OBJECT *) calloc(1, sizeof(STORE_OBJECT));
}
+
 void STORE_OBJECT_free(STORE_OBJECT *data)
{
if (!data) return;



Re: [PATCH SET] libssl: malloc/memset = calloc

2014-05-25 Thread Benjamin Baier
I ran cvs diff on the individual files right in the subdirectory and 
piping the results to one file. Yes I now see how that can be a hurdle.


I'll step it up.

05/25/14 22:32, Ted Unangst wrote:


I didn't notice this before because everything was in different
directories so I pulled it apart by hand, but how are you generating
these diffs? Concatting a dozen diffs together?

These index lines should have some more path information, otherwise
the diff can't be applied. Try running cvs diff from the libssl
directory.




Re: [PATCH 2] libssl: malloc/memset = calloc

2014-05-25 Thread Benjamin Baier
On Sun, 25 May 2014 12:24:17 -0700
Philip Guenther guent...@gmail.com wrote:
 Just say no to casting the return value of malloc/calloc/realloc!

I understand.
fixed.

Index: src/crypto/store/str_lib.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/store/str_lib.c,v
retrieving revision 1.4
diff -u -p -r1.4 str_lib.c
--- src/crypto/store/str_lib.c  17 Apr 2014 21:32:37 -  1.4
+++ src/crypto/store/str_lib.c  25 May 2014 21:38:47 -
@@ -1185,10 +1185,9 @@ int STORE_delete_arbitrary(STORE *s, OPE
 
 STORE_OBJECT *STORE_OBJECT_new(void)
{
-   STORE_OBJECT *object = malloc(sizeof(STORE_OBJECT));
-   if (object) memset(object, 0, sizeof(STORE_OBJECT));
-   return object;
+   return calloc(1, sizeof(STORE_OBJECT));
}
+
 void STORE_OBJECT_free(STORE_OBJECT *data)
{
if (!data) return;







Re: [PATCH 2] followup Speedstep bug

2014-05-22 Thread Benjamin Baier

Works for me.
Since this disables speedstep late in the init, wouldn't it be nice to 
free est_fqlist before disabling (not enabling) speedstep?

Im running this diff for one week now, on amd64.

Index: est.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/est.c,v
retrieving revision 1.31
diff -u -p -r1.31 est.c
--- est.c   10 May 2014 18:59:29 -  1.31
+++ est.c   22 May 2014 14:08:00 -
@@ -418,12 +418,12 @@ est_init(struct cpu_info *ci)
return;

if (est_fqlist-n  2)
-   return;
+   goto nospeedstep;

low = est_fqlist-table[est_fqlist-n - 1].mhz;
high = est_fqlist-table[0].mhz;
if (low == high)
-   return;
+   goto nospeedstep;

perflevel = (cpuspeed - low) * 100 / (high - low);

@@ -439,6 +439,12 @@ est_init(struct cpu_info *ci)

cpu_setperf = est_setperf;
setperf_prio = 3;
+
+   return;
+
+nospeedstep:
+   free(est_fqlist-table, M_DEVBUF);
+   free(est_fqlist, M_DEVBUF);
 }

 void
Index: est.c
===
RCS file: /cvs/src/sys/arch/i386/i386/est.c,v
retrieving revision 1.41
diff -u -p -r1.41 est.c
--- est.c   10 May 2014 18:59:29 -  1.41
+++ est.c   22 May 2014 14:13:32 -
@@ -1177,12 +1177,12 @@ est_init(struct cpu_info *ci, int vendor
return;

if (est_fqlist-n  2)
-   return;
+   goto nospeedstep;

low = est_fqlist-table[est_fqlist-n - 1].mhz;
high = est_fqlist-table[0].mhz;
if (low == high)
-   return;
+   goto nospeedstep;

perflevel = (cpuspeed - low) * 100 / (high - low);

@@ -1198,6 +1198,12 @@ est_init(struct cpu_info *ci, int vendor

cpu_setperf = est_setperf;
setperf_prio = 3;
+
+   return;
+
+nospeedstep:
+   free(est_fqlist-table, M_DEVBUF);
+   free(est_fqlist, M_DEVBUF);
 }

 void


On 05/10/14 21:02, Philip Guenther wrote:

On Sat, May 10, 2014 at 4:06 AM, Benjamin Baier program...@netzbasis.dewrote:


After setting cpu clock to the minimum value in my BIOS, SpeedStep paniced
on me.
dmesg before and after patching at
http://netzbasis.de/openbsd/speedstep/

The patch below works for me, tested on amd64.
low == high == 800
cpuspeed == 798 (!)



Thanks for the report!

kettenis@ noted that there's no point in enabling speedstep if there
nothing to range over, so I've committed a slightly different diff to do
that instead.

Philip Guenther





[PATCH] Speedstep bug

2014-05-10 Thread Benjamin Baier

Hi tech@

After setting cpu clock to the minimum value in my BIOS, SpeedStep 
paniced on me.

dmesg before and after patching at
http://netzbasis.de/openbsd/speedstep/

The patch below works for me, tested on amd64.
low == high == 800
cpuspeed == 798 (!)

--- sys/arch/amd64/amd64/est.c.orig Fri May  9 00:14:22 2014
+++ sys/arch/amd64/amd64/est.c  Sat May 10 11:40:01 2014
@@ -424,7 +424,11 @@

low = est_fqlist-table[est_fqlist-n - 1].mhz;
high = est_fqlist-table[0].mhz;
-   perflevel = (cpuspeed - low) * 100 / (high - low);
+   if (low == high) {
+   perflevel = 0;
+   } else {
+   perflevel = (cpuspeed - low) * 100 / (high - low);
+   }

/*
 * OK, tell the user the available frequencies.

--- sys/arch/i386/i386/est.c.orig   Fri May  9 00:14:22 2014
+++ sys/arch/i386/i386/est.cSat May 10 11:40:01 2014
@@ -424,7 +424,11 @@

low = est_fqlist-table[est_fqlist-n - 1].mhz;
high = est_fqlist-table[0].mhz;
-   perflevel = (cpuspeed - low) * 100 / (high - low);
+   if (low == high) {
+   perflevel = 0;
+   } else {
+   perflevel = (cpuspeed - low) * 100 / (high - low);
+   }

/*
 * OK, tell the user the available frequencies.



Re: cpsw device timeouts

2014-04-17 Thread Benjamin Baier

A 3rd check against a self compiled kernel based on the latest anoncvs tree
without any patches shows the same behaviour as described below.

# i=219
# while [ $i -le 226 ];do
 ping -f -n -c100 -s$i 192.168.7.1
 i=$(( $i + 1 ))
 done
PING 192.168.7.1 (192.168.7.1): 219 data bytes
--- 192.168.7.1 ping statistics ---
101 packets transmitted, 100 packets received, 1.0% packet loss
round-trip min/avg/max/std-dev = 2.106/5.609/18.494/2.818 ms
PING 192.168.7.1 (192.168.7.1): 220 data bytes
--- 192.168.7.1 ping statistics ---
101 packets transmitted, 100 packets received, 1.0% packet loss
round-trip min/avg/max/std-dev = 2.076/8.117/17.884/3.961 ms
PING 192.168.7.1 (192.168.7.1): 221 data bytes
--- 192.168.7.1 ping statistics ---..^C
69 packets transmitted, 0 packets received, 100.0% packet loss
PING 192.168.7.1 (192.168.7.1): 222 data bytes
--- 192.168.7.1 ping statistics ---
100 packets transmitted, 100 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 2.075/5.448/9.705/1.633 ms
PING 192.168.7.1 (192.168.7.1): 223 data bytes
--- 192.168.7.1 ping statistics ---
100 packets transmitted, 100 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 4.089/5.867/8.911/0.821 ms
PING 192.168.7.1 (192.168.7.1): 224 data bytes
--- 192.168.7.1 ping statistics ---
100 packets transmitted, 100 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 2.075/5.684/7.629/1.196 ms
PING 192.168.7.1 (192.168.7.1): 225 data bytes
--- 192.168.7.1 ping statistics ---
101 packets transmitted, 100 packets received, 1.0% packet loss
round-trip min/avg/max/std-dev = 2.075/10.302/17.548/5.581 ms
PING 192.168.7.1 (192.168.7.1): 226 data bytes
--- 192.168.7.1 ping statistics ---
101 packets transmitted, 100 packets received, 1.0% packet loss
round-trip min/avg/max/std-dev = 2.075/5.893/17.578/3.663 ms

dmesg
OpenBSD 5.5-current (GENERIC-OMAP) #0: Wed Apr 16 21:56:28 CEST 2014
r...@bbb1.hexa.homeunix.net:/usr/src/sys/arch/armv7/compile/GENERIC-OMAP
real mem  = 536870912 (512MB)
avail mem = 518746112 (494MB)
warning: no entropy supplied by boot loader
mainbus0 at root
cpu0 at mainbus0: ARM Cortex A8 R3 rev 2 (ARMv7 core)
cpu0: DC enabled IC enabled WB disabled EABT branch prediction enabled
cpu0: 32KB(64b/l,4way) I-cache, 32KB(64b/l,4way) wr-back D-cache
omap0 at mainbus0: BeagleBone
prcm0 at omap0 rev 0.2
sitaracm0 at omap0: control module, rev 1.0
intc0 at omap0 rev 5.0
edma0 at omap0 rev 0.0
dmtimer0 at omap0 rev 3.1
dmtimer1 at omap0 rev 3.1
omdog0 at omap0 rev 0.1
omgpio0 at omap0: rev 0.1
gpio0 at omgpio0: 32 pins
omgpio1 at omap0: rev 0.1
gpio1 at omgpio1: 32 pins
omgpio2 at omap0: rev 0.1
gpio2 at omgpio2: 32 pins
omgpio3 at omap0: rev 0.1
gpio3 at omgpio3: 32 pins
omap0: device tiiic unit 0 not configured
omap0: device tiiic unit 1 not configured
omap0: device tiiic unit 2 not configured
ommmc0 at omap0
sdmmc0 at ommmc0
ommmc1 at omap0
sdmmc1 at ommmc1
com0 at omap0: ti16750, 64 byte fifo
com0: console
cpsw0 at omap0: version 1.12 (0), address 90:59:af:58:ce:17
ukphy0 at cpsw0 phy 0: Generic IEEE 802.3u media interface, rev. 1: OUI 
0x0001f0, model 0x000f

scsibus0 at sdmmc0: 2 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0: SD/MMC, Drive #01,  SCSI2 0/direct fixed
sd0: 7384MB, 512 bytes/sector, 15122432 sectors
scsibus1 at sdmmc1: 2 targets, initiator 0
sd1 at scsibus1 targ 1 lun 0: SD/MMC, Drive #01,  SCSI2 0/direct fixed
sd1: 1832MB, 512 bytes/sector, 3751936 sectors
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
boot device: sd0
root on sd0a (6a8ab8283a822f44.a) swap on sd0b dump on sd0b

- Ben

On 04/16/14 20:49, Benjamin Baier wrote:
I patched this against (1st) the latest anoncvs tree and (2nd) against 
your

cpsw patch from 04/12/14 (2).
Both times it works (compile, boot) and so I tested the timeout bug 
described at

http://marc.info/?l=openbsd-bugsm=138275913126582w=2

First i can reproduce the timeout bug with the latest snapshot kernel
OpenBSD 5.5 (GENERIC-OMAP) #11: Sat Mar  8 12:52:57 EST 2014

With the patched kernels (1) and (2) the timeout shiftet.
# ping -f -n -c100 -s289 ip
runs with 0% packet loss
# ping -f -n -c100 -s225 ip
runs with 0% packet loss
# ping -f -n -c100 -s221 ip
runs with complete packet loss (100%), sometimes I get 1 return packet.

All others -s1 up to -s1000 come back mixed, with 1/3rd coming back with
max. 1 lost packet and 2/3rd coming back with 0% packet loss.

- Ben

On 04/14/14 20:18, Brandon Mercer wrote:

whoops, small typo in the previous diff:

cvs diff: Diffing sys/arch/armv7/omap/
Index: sys/arch/armv7/omap//if_cpsw.c
===
RCS file: /cvs/src/sys/arch/armv7/omap/if_cpsw.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 if_cpsw.c
--- sys/arch/armv7/omap//if_cpsw.c  26 Nov 2013 20:33:11 -
1.21
+++ sys/arch/armv7/omap//if_cpsw.c  14 Apr 2014 17:37:27 -
@@ -816,6 +816,8 @@ cpsw_init

Re: cpsw device timeouts

2014-04-16 Thread Benjamin Baier

I patched this against (1st) the latest anoncvs tree and (2nd) against your
cpsw patch from 04/12/14 (2).
Both times it works (compile, boot) and so I tested the timeout bug 
described at

http://marc.info/?l=openbsd-bugsm=138275913126582w=2

First i can reproduce the timeout bug with the latest snapshot kernel
OpenBSD 5.5 (GENERIC-OMAP) #11: Sat Mar  8 12:52:57 EST 2014

With the patched kernels (1) and (2) the timeout shiftet.
# ping -f -n -c100 -s289 ip
runs with 0% packet loss
# ping -f -n -c100 -s225 ip
runs with 0% packet loss
# ping -f -n -c100 -s221 ip
runs with complete packet loss (100%), sometimes I get 1 return packet.

All others -s1 up to -s1000 come back mixed, with 1/3rd coming back with
max. 1 lost packet and 2/3rd coming back with 0% packet loss.

- Ben

On 04/14/14 20:18, Brandon Mercer wrote:

whoops, small typo in the previous diff:

cvs diff: Diffing sys/arch/armv7/omap/
Index: sys/arch/armv7/omap//if_cpsw.c
===
RCS file: /cvs/src/sys/arch/armv7/omap/if_cpsw.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 if_cpsw.c
--- sys/arch/armv7/omap//if_cpsw.c  26 Nov 2013 20:33:11 -
1.21
+++ sys/arch/armv7/omap//if_cpsw.c  14 Apr 2014 17:37:27 -
@@ -816,6 +816,8 @@ cpsw_init(struct ifnet *ifp)
  
 cpsw_write_4(sc, CPSW_CPDMA_SOFT_RESET, 1);

 while(cpsw_read_4(sc, CPSW_CPDMA_SOFT_RESET)  1);
+
+   cpsw_write_4(sc, CPSW_SS_FLOW_CONTROL, 0);
  
 for (i = 0; i  8; i++) {

 cpsw_write_4(sc, CPSW_CPDMA_TX_HDP(i), 0);
Index: sys/arch/armv7/omap//if_cpswreg.h
===
RCS file: /cvs/src/sys/arch/armv7/omap/if_cpswreg.h,v
retrieving revision 1.5
diff -u -p -u -r1.5 if_cpswreg.h
--- sys/arch/armv7/omap//if_cpswreg.h   15 Nov 2013 14:31:52 -
1.5
+++ sys/arch/armv7/omap//if_cpswreg.h   14 Apr 2014 18:08:52 -
@@ -39,6 +39,7 @@
  #define CPSW_SS_SOFT_RESET (CPSW_SS_OFFSET + 0x08)
  #define CPSW_SS_STAT_PORT_EN   (CPSW_SS_OFFSET + 0x0C)
  #define CPSW_SS_PTYPE  (CPSW_SS_OFFSET + 0x10)
+#define CPSW_SS_FLOW_CONTROL   (CPSW_SS_OFFSET + 0x24)
  
  #define CPSW_PORT_OFFSET   0x0100

  #define CPSW_PORT_P_TX_PRI_MAP(p)  (CPSW_PORT_OFFSET + 0x118 +
((p-1) * 0x100))