MCPcopy Create free account
hub / github.com/NVIDIA/open-gpu-kernel-modules / nv_printf

Function nv_printf

kernel-open/nvidia/os-interface.c:853–900  ·  view source on GitHub ↗

* nv_printf() prints to the kernel log for the driver. * Returns the number of characters written. */

Source from the content-addressed store, hash-verified

851 * Returns the number of characters written.
852 */
853int NV_API_CALL nv_printf(NvU32 debuglevel, const char *printf_format, ...)
854{
855 va_list arglist;
856 int chars_written = 0;
857
858 if (debuglevel >= ((cur_debuglevel >> 4) & 0x3))
859 {
860 size_t length;
861 unsigned long flags;
862
863 // When printk is called to extend the output of the previous line
864 // (i.e. when the previous line did not end in \n), the printk call
865 // must contain KERN_CONT. Older kernels still print the line
866 // correctly, but KERN_CONT was technically always required.
867
868 // This means that every call to printk() needs to have a KERN_xxx
869 // prefix. The only way to get this is to rebuild the format string
870 // into a new buffer, with a KERN_xxx prefix prepended.
871
872 // Unfortunately, we can't guarantee that two calls to nv_printf()
873 // won't be interrupted by a printk from another driver. So to be
874 // safe, we always append KERN_CONT. It's still technically wrong,
875 // but it works.
876
877 // The long-term fix is to modify all NV_PRINTF-ish calls so that the
878 // string always contains only one \n (at the end) and NV_PRINTF_EX
879 // is deleted. But that is unlikely to ever happen.
880
881 length = strlen(printf_format);
882 if (length < 1)
883 return 0;
884
885 NV_SPIN_LOCK_IRQSAVE(&nv_error_string_lock, flags);
886
887 // KERN_CONT changed in the 3.6 kernel, so we can't assume its
888 // composition or size.
889 memcpy(nv_error_string, KERN_CONT, sizeof(KERN_CONT) - 1);
890 memcpy(nv_error_string + sizeof(KERN_CONT) - 1, printf_format, length + 1);
891
892 va_start(arglist, printf_format);
893 chars_written = vprintk(nv_error_string, arglist);
894 va_end(arglist);
895
896 NV_SPIN_UNLOCK_IRQRESTORE(&nv_error_string_lock, flags);
897 }
898
899 return chars_written;
900}
901
902NvS32 NV_API_CALL os_snprintf(char *buf, NvU32 size, const char *fmt, ...)
903{

Callers 15

nv_cxl_get_hdm_base_addrFunction · 0.85
nv_resize_pcie_barsFunction · 0.85
nv_pci_validate_barsFunction · 0.85
nv-pci.cFile · 0.85
nv_pci_remove_helperFunction · 0.85

Calls 1

memcpyFunction · 0.85

Tested by

no test coverage detected